1. Introduction
Laravel's hash façade provides a secure bcrypt hashing algorithm for storing user passwords. If you are using the Laravel app's own Authcontroller controller, the Bcrypt will be automatically used for registration and authentication.
Bcrypt is a great choice for hashing passwords because the "working factor" is adjustable, which means that the time it takes to generate a hash increases as the hardware function increases.
2. Basic use
You can call the Make method hash store password on the hash façade:
Fill ([ ' Password ' = hash::make ($request->newpassword) ])->save ();} }
In addition, you can use the global auxiliary function Bcrypt:
Bcrypt (' Plain-text ');
Verify Hash password
The check method allows you to verify that a given native string and a given hash are equal, however, if you are using Laravel's own Authcontroller (see the User authentication section), you do not need to use this method directly because the self-brought authentication controller automatically calls the method:
if (Hash::check (' Plain-text ', $hashedPassword)) { //password match ...}
Check if password needs to be re-hashed
The Needsrehash method allows you to determine whether the work factor used by the hash evaluator has changed since the last password was hashed:
if (Hash::needsrehash ($hashed)) { $hashed = hash::make (' Plain-text ');}