📅  最后修改于: 2023-12-03 15:32:34.760000             🧑  作者: Mango
Laravel Hash is a built-in feature in Laravel that helps to securely hash passwords. This package comes with various features that increase the security of your application's password storage.
To use Laravel Hash, you first need to install Laravel. Then, add a password field to your User model, which would be the attribute that Laravel Hash will be using.
Example
use Illuminate\Support\Facades\Hash;
class User extends Model
{
protected $fillable = ['name', 'email', 'password'];
public function setPasswordAttribute($password)
{
$this->attributes['password'] = Hash::make($password);
}
}
In the example above, the setPasswordAttribute()
method automatically hashes the user's password when assigned using the Hash::make()
method.
To verify a password, you can use the Hash::check()
method in your authentication logic.
Example
if (Hash::check('password', $hashedPassword)) {
// The passwords match...
}
Laravel Hash is a powerful and effective function that provides secure password hashing for your Laravel application. Using Laravel Hash gives your application another level of security and flexibility, which is a must-have for any secure web application.