我已经使用Auth中间件完成了登录功能,其中使用了Bcrypt加密方法。登录功能正常。但是,我们需要处理设置密码功能并需要验证旧密码。但是每次Bcrypt方法都会更改密码字符串,因此表中先前存储的密码的bcrypt字符串与以设置密码形式手动输入的密码不匹配。因此,如果旧密码字段与表中现有的已保存密码不匹配,如何验证旧密码字段。
$credentials = request(['email', 'password']);
$user=Auth::attempt($credentials);
您正在使用Laravel,因此应使用Hash
来处理密码。
这里是您需要了解的所有信息:https://laravel.com/docs/6.x/hashing#basic-usage
简而言之,您可以通过以下方式创建和验证密码:
$hashedPassword = Hash::make($request->password);
if (Hash::check('entered-password-by-user', $hashedPassword)) {
// The passwords match...
}
当然,不要忘记包含哈希外观:use Illuminate\Support\Facades\Hash;