Laravel Hashing: Basic Usage

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Http\Controllers\Controller;

class UpdatePasswordController extends Controller
{
    /**
     * Update the password for the user.
     *
     * @param  Request  $request
     * @return Response
     */
    public function update(Request $request)
    {
        // Validate the new password length...

        $request->user()->fill([
            'password' => Hash::make($request->newPassword)
        ])->save();
    }
}

Adjusting The Bcrypt Work Factor

$hashed = Hash::make('password', [
    'rounds' => 12
]);

Adjusting The Argon2 Work Factor

$hashed = Hash::make('password', [
    'memory' => 1024,
    'time' => 2,
    'threads' => 2,
]);

Verifying A Password Against A Hash

If (Hash::check('plain-text', $hashedPassword)) {
    // The passwords match...
}

Checking If A Password Needs To Be Rehashed

If (Hash::needsRehash($hashed)) {
    $hashed = Hash::make('plain-text');
}

Laravel Hashing: Basic Usage — Structure map

Clickable & Draggable!

Laravel Hashing: Basic Usage — Related pages: