我的注册表单正在运行,它将用户存储到数据库,但是当用户登录时,Auth::attempt() 返回 false。这是我的登录代码。我将密码以 sha1 加密形式存储在 db 中。
Route::post('login',function(){
$creds=array(
'email' => Input::get('email'),
'password' => sha1(Input::get('password'))
);
$auth = Auth::attempt($creds);
dd($auth);
即使您可以按照中所述实现服务提供者这个帖子 https://stackoverflow.com/questions/17710897/how-to-use-sha1-encryption-instead-of-bcrypt-in-laravel-4,您可以通过使用手动完成其他验证方法 https://laravel.com/docs/5.5/authentication#other-authentication-methods
This means you can do like so:
//....
try{
$user = User::where('email', Input::get('email'))
->where('password', sha1(Input::get('password')))->firstOrFail();
Auth::login($user);
} catch (ModelNotFoundException $e)
return ['Username or password Incorrect'];
}
然而最好的办法是使用bcrypt()
在 Laravel 中,但如果没有 bcrypt 选项,上面的方法应该可以工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)