29.07.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Hashing 265<br />

.<br />

22<br />

23 // Validate the new password length...<br />

24<br />

25 $user->fill([<br />

26 'password' => Hash::make($request->newPassword)<br />

27 ])->save();<br />

28 }<br />

29 }<br />

Alternatively, you may also use the global bcrypt helper function:<br />

.<br />

1 bcrypt('plain-text');<br />

Verifying A Password Against A Hash<br />

The check method allows you to verify that a given plain-text string corresponds to a given hash.<br />

However, if you are using the AuthController included with Laravel, you will probably not need<br />

to use this directly, as the included authentication controller automatically calls this method:<br />

.<br />

1 if (Hash::check('plain-text', $hashedPassword)) {<br />

2 // The passwords match...<br />

3 }<br />

Checking If A Password Needs To Be Rehashed<br />

The needsRehash function allows you to determine if the work factor used by the hasher has changed<br />

since the password was hashed:<br />

.<br />

1 if (Hash::needsRehash($hashed)) {<br />

2 $hashed = Hash::make('plain-text');<br />

3 }

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!