Auth::attempt() is not working in Laravel 5.5

2019-05-25 04:14发布

My registration form is working and it store users to db but when user login then Auth::attempt() return false. Here is my code for login. I store the password in db in sha1 encription.

Route::post('login',function(){
$creds=array(
        'email' => Input::get('email'),
        'password' => sha1(Input::get('password'))
    );
$auth = Auth::attempt($creds);

dd($auth);

3条回答
看我几分像从前
2楼-- · 2019-05-25 04:38

I solved it by converting the registering user password to sha1 and then to laravel hashing encryption like so Hash::make(sha1(Input::get('password')));

At login time I do like below

Hash::make(sha1(Input::get('password')))

Then $auth = Auth::attempt($creds); worked.

查看更多
Emotional °昔
3楼-- · 2019-05-25 04:47

Even though you can implement a Service provider as describe in this post, You can do it manually by with using other auth method

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'];
}

The best thing however is to use the bcrypt() in Laravel but the above should work in case bcrypt is no option.

查看更多
迷人小祖宗
4楼-- · 2019-05-25 04:51

Try this -

Route::post('login',function(){

$auth = Auth::attempt(['email'=>Input::get('email'),'password'=>Input::get('password')],$remember ? true : false);

dd($auth);
});

Hope this will work for you.

查看更多
登录 后发表回答