如何在数据库中加密/哈希密码,但使其对网站管理员可用?

huangapple go评论88阅读模式
英文:

How to encrypt/hash passwords in database, but make available to site admin?

问题

所以网站身份验证的基本规则之一是永远不要将未加密的密码写入数据库。我通常在创建用户帐户时加入散列密码的功能,以便您不能打开数据库并在查询中看到密码。但由于散列是单向的,对于需要访问用户帐户中的用户名和密码的网站管理员来说,最好的方式是什么?

我明白了,如果有一种简单的方法可以恢复明文密码,那么一开始散列密码就没有意义了。但假设管理员需要以某个特定用户的身份登录网站,也许解决办法是添加一个仅供网站管理员使用的“模拟登录”功能?或者,如果这不是一种世界级黑客感兴趣的网站,也许可以使用双向加密解密系统来处理密码?

英文:

So one of the basic rules of website authentication is never to write unencrypted passwords to the database. I typically put in functionality to hash passwords when user accounts are created, so that you can't just open up the DB and see the password in a query. But since hashing is one-way, what's the best way for website admins who need access to usernames and passwords in user accounts to retrieve passwords?

I get that if there was a simple way to recover the clear-text password, there would be no point in hashing the passwords to begin with. But say an admin needs to log into the site as a certain user, then maybe the solution is to add a "log in as" feature available only to site admins? Or, if it's not a site that world-class hackers would be interested in, maybe it's okay to use a 2-way encrypt-decrypt system for passwords?

答案1

得分: 1

绝对要采用“以某人身份登录”的方式,永远不要尝试使密码可检索。要达到您的目标并不需要知道密码,如果用户重复使用密码,这将不仅危及您的网站,还可能危及其他网站。

密码哈希不仅包括单向哈希,还使用盐和密钥拉伸来减轻彩虹表和暴力攻击。声称了解密码是可以的信息来源是完全错误的!

英文:

Definitively go the "Log in as" route and never try to make the passwords retrievable. It is not necessary to know the password to reach your goal and it would endanger not only your site, but other sites as well, if the user reused the password.

Password-hashing not only includes a one-way hash, it also uses salting and key-stretching to mitigate rainbow tables and brute-force attacks. The sources telling about knowing the passwords to be ok, are just plain wrong!

huangapple
  • 本文由 发表于 2023年6月9日 01:42:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76434432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定