具有不同加密检查的 Laravel 身份验证。沙256

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41697355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:08:45  来源:igfitidea点击:

Laravel Authentication with different encryption check. Sha256

phplaravelencryption

提问by Classified

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.

我已经与一个问题斗争了一段时间了。我想在我的网站上使用 Laravel,但由于我们项目中的一些其他限制,我只能使用 SHA256 作为密码加密。

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)

基本上我的问题由 Laravel 中的一个函数组成,该函数用于检查用户数据是否正确(检查用户是否可以登录)由于我在加密方面的差异而对我不起作用(至少这是我的理论)

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.

无论密码是否正确,此函数始终返回 false,我认为这是因为加密方式不同。

Anybody know if there's a fix for this?

有谁知道有没有解决办法?

采纳答案by Classified

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

我在 Arun Code 和 Andrew 的上述评论的帮助下解决了这个问题。

For anyone else with this issue I suggest reading this

对于有此问题的其他人,我建议阅读此内容

回答by Arun Code

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.

在这里SHA256($password)您可以调用与用于加密相同的函数并检查它。

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

在这种情况下,SHA256(虚拟函数)将散列您传递的密码并匹配该值。

EDIT 1

编辑 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.

现在,在登录时,您可以使用相同的 SHA256 函数来加密输入密码并检查您的数据库。