Laravel类“HASH”未找到。

5

在验证规则之后,我想要检查当前输入的密码是否与数据库中保存的哈希密码匹配。我正在使用以下代码,但是出现了错误:

错误代码:

Symfony \ Component \ Debug \ Exception \ FatalErrorException

Class 'HASH' not found

我的控制器行为:

public function update($id)
{
    $rules = array(
        'name'       => 'required|alpha',
        'family'     => 'required',
        'email'      => 'required',
        'password'   => 'required|confirmed',
        'password_confirmation'=>'required',
    );

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

    if ($validator->fails()) {
        return Redirect::to('/admin/profile')
            ->withErrors($validator)
            ->withInput();
    } 
    else 
    {
        $currentPassword = User::find($id);
        if ( $currentPassword == HASH::make(Input::get('currpassword')) ){
            return Redirect::route('/admin/profile')
                ->with('message', 'Password Match Error')
                ->withInput();
        }

    }
}
3个回答

26

我也遇到了这个问题。但是最终找到了解决方法。请在您的代码文件顶部包含以下路径。然后问题可能会得到解决。

use Illuminate\Support\Facades\Hash;

7
应该使用 Hash::make,而不是 HASH::make

1
在您的控制器文件中的顶部添加以下内容:

use Hash
// and use Hash::make instead of HASH::make
Hash::make(Input::get('currpassword'))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接