如何重新散列 Laravel 密码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19220925/
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 08:32:00  来源:igfitidea点击:

How to re-hash Laravel passwords?

hashpasswordslaravel

提问by user2002495

I'm making a forget password feature in my web app, problem is I store user's password using:

我正在我的网络应用程序中创建忘记密码功能,问题是我使用以下方法存储用户密码:

Hash::make('_their_password_')

Hash::make('_their_password_')

Is there any way to re-hash it back or any recommended approach for this?

有什么方法可以重新哈希它或任何推荐的方法吗?

回答by svk

The point of hashing a password is that it's (supposed to be) an irreversible operation. If your database is compromised, the attacker will gain access to the hashes, but not to the passwords. That way the attacker can't log in with the users' passwords on other sites.

散列密码的要点在于它(应该是)不可逆的操作。如果您的数据库遭到破坏,攻击者将获得对哈希值的访问权限,但无法访问密码。这样攻击者就无法在其他站点上使用用户的密码登录。

Make a "we'll reset your password" feature instead of a "we'll send you your password" feature.

制作“我们将重置您的密码”功能,而不是“我们将向您发送您的密码”功能。

Note that there are also other best practicesyou absolutely should be following regarding password hashing, to make sure the "supposed to be" above actually holds, and to further minimize the impact if your site is compromised. Laravel's Hashclass seems to already be using the password-appropriate hash function Bcrypt. However, make sure you're using a salt when you're hashing your password.

请注意,还有其他关于密码散列的最佳实践,您绝对应该遵循,以确保上面的“应该是”确实成立,并在您的网站遭到入侵时进一步减少影响。Laravel 的Hash类似乎已经在使用适合密码的哈希函数 Bcrypt。但是,请确保在对密码进行哈希处理时使用了盐。

回答by devo

The Laravel's Hash method cannot be reversed.

Laravel 的 Hash 方法无法逆转。

One way encryption is the best way to store user passwords, or other sensitive data.

一种加密方式是存储用户密码或其他敏感数据的最佳方式。

One way means that your data can be converted into an encrypted string, but due to a complex algorithm with painful maths, reversing the process is not possible. This makes storing passwords a doddle! Your customers don't have to worry about you knowing their passwords, but you are still able to compare them (by hashing the password they provide) or change the password if needed.

一种方法意味着您的数据可以转换为加密字符串,但由于复杂的算法和痛苦的数学,逆转这个过程是不可能的。这使得存储密码变得轻而易举!您的客户不必担心您知道他们的密码,但您仍然可以比较它们(通过散列他们提供的密码)或在需要时更改密码。

If you need to reverse, you can use Crypterclass.

如果需要反转,可以使用Crypterclass。

$secret = Crypter::encrypt('I actually like Hello Kitty');
$decrypted_secret = Crypter::decrypt($secret);

Read more about encryption here http://codehappy.daylerees.com/encryption

在此处阅读有关加密的更多信息http://codehappy.daylerees.com/encryption