Varun Malhotra
Varun Malhotra

Reputation: 1202

Default hash type of passwords in Laravel

What type of hashing algorithm is used by default for passwords in Laravel. If we want to change the password in the database then how can we identify the hash type of the password?

Upvotes: 6

Views: 9387

Answers (2)

seb_dom
seb_dom

Reputation: 113

You can also use laravel/tinker to update/create/delete/etc data in the DB table from console, for example:

php artisan tinker
>>$user = App\Models\User::find(2);// or User::find(2)find user with id 2
>>$user->password = bcrypt('test83403'); //change password
>>$user->save(); //save the new change

Upvotes: 0

LuFFy
LuFFy

Reputation: 9307

According to Laravel Documentation :

The Laravel Hash facade provides secure Bcrypt hashing for storing user passwords. If you are using the AuthController controller that is included with your Laravel application, it will be take care of verifying the Bcrypt password against the un-hashed version provided by the user.

Likewise, the user Registrar service that ships with Laravel makes the proper bcrypt function call to hash stored passwords.

Hashing A Password Using Bcrypt

$password = Hash::make('secret');

You may also use the bcrypt helper function:

$password = bcrypt('secret');

Verifying A Password Against A Hash

if (Hash::check('secret', $hashedPassword))
{
    // The passwords match...
}

Checking If A Password Needs To Be Rehashed

if (Hash::needsRehash($hashed))
{
    $hashed = Hash::make('secret');
}

Upvotes: 8

Related Questions