dsa88885555
dsa88885555
2017-01-17 12:35
浏览 329
已采纳

Laravel身份验证使用不同的加密检查。 SHA256

I've struggled with a problem for a while now. I want to use Laravel for my website BUT I can only use SHA256 as the password encryption because of some other limitations in our project.

Basicly my problem consists of a function within Laravel that is used to check if the userdata is correct (Checks if the user can login) does not work for me because of my difference in encryption (Atleast that's my theory)

Auth::attempt(['username' => $username, 'password' => $password]

This function always returns false, no matter if the password is correct and I assume it's because of the difference in encryption.

Anybody know if there's a fix for this?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongzhong5833
    dongzhong5833 2017-01-17 13:45
    已采纳

    I fixed this issue with the help of the above comments from Arun Code and Andrew.

    For anyone else with this issue I suggest reading this

    点赞 评论
  • ds12093213
    「已注销」 2017-01-17 12:42
    Auth::attempt(['username' => $username, 'password' => SHA256($password)]);
    

    Here SHA256($password) you can call the function as the same which used for encryption and check it.

    In this case, SHA256 (dummy function) will hash the password you passed and match the value.

    EDIT 1

    Sample Code for registration

    $users = User::create([
    'name' => $name,
    'email' => $email,
    ....
    ....
    'password' => SHA256($password)
     ]);
    
    //to login with the above creds
    Auth::login($users);
    

    Now while login you can use the same SHA256 function to encrypt the input password and check with your database.

    点赞 评论

相关推荐