Laravel 4.2验证规则-当前密码必须匹配DB值


Laravel 4.2 Validation Rules - Current Password Must Match DB Value

在密码重置时由用户供给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哈希。