gpt4 book ai didi

php - Laravel 4.2 验证规则 - 当前密码必须匹配数据库值

转载 作者:可可西里 更新时间:2023-11-01 12:38:12 27 4
gpt4 key购买 nike

在密码重置表单中,用户提供current_passwordpasswordpassword-confirmation。有没有办法在验证规则中指定 current_password(它的哈希值)必须与数据库值匹配?

目前我有这个:

$rules = array(
'current_password' => 'required',
'password' => 'required|confirmed|min:22'
);

谢谢。

更新

感谢@ChrisForrence 和@Ben,我想出了以下非常有效的方法!非常感激。希望这会帮助其他人:

Validator::extend('hashmatch', function($attribute, $value, $parameters)
{
return Hash::check($value, Auth::user()->$parameters[0]);
});
$messages = array(
'hashmatch' => 'Your current password must match your account password.'
);
$rules = array(
'current_password' => 'required|hashmatch:password',
'password' => 'required|confirmed|min:4|different:current_password'
);

$validation = Validator::make( Input::all(), $rules, $messages );

最佳答案

你不能,bcrypt 散列是唯一的(它们有自己的随机盐)所以即使你知道用户的明文密码你也不能做散列到-哈希比较。

您实际上可以通过执行 Hash::check('plain text password', 'bcrypt hash') 根据 bcrypt 哈希检查纯文本密码在你的 Controller 上。

关于php - Laravel 4.2 验证规则 - 当前密码必须匹配数据库值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24830119/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com