保护数据库中的密码字段
可能的重复:
在数据库中存储密码的最佳方法
我有一个数据库(mySQL)其中表 USERS 具有以下结构:
- UserID (varchar)
- Passwd (varchar)
- Name (varchar)
- BancAccount (varchar)
Passwd 和 BancAccount 是数据库中的纯文本。从 PHP 代码来看,登录完成后,它将用户输入的 UserID 和 Passwd 与数据库中的结果进行比较。
我想让它更加安全,这样如果任何人能够闯入数据库,他就看不到这两个关键字段。有什么建议吗?
谢谢
Possible Duplicate:
Best way to store password in database
I have a database (mySQL) where the table USERS has this structure:
- UserID (varchar)
- Passwd (varchar)
- Name (varchar)
- BancAccount (varchar)
Passwd and BancAccount are plain text on the database. From the PHP code, when login is done, it compares the user input for UserID and Passwd with the results from the database.
I would like to make it more secure, so that if anyone is able to break into the database, he cannot see these two critical fields. Any suggestions?
THANKS
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试使用 PHP crypt 函数并使用数据库来存储盐,按照 Neal 的说法进行跟进,确保你尝试使用一些模糊性来隐藏它......但是你需要盐来将用户输入与稍后进行比较。
PHP Crypt()
Try using the PHP crypt function and use the database to to store the salt as well, to follow up with what Neal says, make sure you try to use some obscurity to hide it as well...but you'll need the salt to compare the user input against later.
PHP Crypt()
那么你可以用盐来哈希密码。并且有一个完全独立的银行账户表,该表以某种方式与该表链接,但非常模糊。
well you can hash with a salt the password. and have a completely seperate table for thebank accounts that is linked somehow to that table but very obscurely.
您绝对不应该以纯文本形式存储密码,而只存储密码的哈希值,最多是加盐哈希< /a>.
使用哪种哈希函数以及如何选择盐也是一个重要的问题。 许多人建议使用bcrypt作为哈希函数密码有一个成本参数来调整生成哈希值的计算成本(成本越高,暴力攻击持续的时间越长)。并且盐应该是随机值并且对于每个密码都是唯一的。
You should definitely not store the password in plain but only a hash of it, at best a salted hash.
Which hash function you use and how the salt is chosen is also an important question. Many people suggest to use bcrypt as the hash function for passwords that has a cost parameter to adjust the computational costs of generating the hash value (the more expensive the longer brute-force attacks will last). And the salt should be a random value and unique for each password.
我建议将包含密码的连接字符串放在一起;也叫“Salt and Pepper”密码,然后用SHA1加密。然后在检查数据库字段时使用相同的算法。
使用动态盐(例如随机生成的字符串、数字、日期或时间戳)只是创造力的冰山一角。
I'd suggest putting together a concenated string containing the password; also called to "Salt and Pepper" the password, then encrypt it with SHA1. Then you use the same algorithm when checking the database fields.
Using dynamic salts like randomly generated strings, numbers, dates or timestamps are only the tip of the iceberg of creativity.