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

Pet*_*rKA 8 php validation bcrypt laravel-4

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

目前我有这个:

$rules = array(
    'current_password' => 'required',
    'password'         => 'required|confirmed|min:22'
); 
Run Code Online (Sandbox Code Playgroud)

谢谢.

UPDATE

感谢@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 );
Run Code Online (Sandbox Code Playgroud)

Ben*_*Ben 3

你不能,bcrypt哈希值是唯一的(它们包含自己的随机盐),因此即使你知道用户的纯文本密码,你也无法进行哈希值与哈希值的比较。

bcrypt您实际上可以做的是通过Hash::check('plain text password', 'bcrypt hash')在控制器上执行操作来检查纯文本密码与哈希值。