crypt() 的替代方法
我正在编写脚本并需要保存密码。出于开发目的,我一直使用 crypt() 函数,因为它简单且可用。现在我已经完成了大部分工作,我想用更好、更一致的东西来替换它。
我担心的一些问题是:
- 并非所有系统都支持所有算法,
- 有时盐会预先添加到结果中(似乎是一个安全问题)
我想要一些可以与 PHP 4.3+ 一起使用的东西。
有什么可用的,或者我应该坚持使用 crypt() 吗?我考虑过使用md5(md5($password).$salt)
。感谢您的见解。
I am working on a script and need to save passwords. For development purposes, I have been using the crypt()
function because it was easy and available. Now that I am mostly done, I want to replace it with something a little better and more consistent.
Some of the concerns I have are:
- not all algorithms are supported on every system
- sometimes the salt is pre-pended to the result (seems like a security problem)
I want something that works with PHP 4.3+.
Is there anything available, or should I stick with crypt()
? I thought about using md5(md5($password).$salt)
. Thanks for the insight.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
crypt
没有任何问题,如果你的服务器不支持,请使用其他服务器。
您应该永远使用MD5来散列密码(甚至SHA1)
使用bcrypt(
crypt
的河豚方法)或pbkdf2是 pbkdf2 的实现:
使用 PHP 加密密码使用 RSA PBKDF2 标准进行存储
有关原因和方式的更多信息,请参见此处:
There is nothing wrong with
crypt
If your server does not support it, use another server.
You should NEVER use MD5 for hashing passwords (or even SHA1 for that matter)
Use either bcrypt (the blowfish method of
crypt
) or pbkdf2There is an implementation of pbkdf2 here:
Encrypting Passwords with PHP for Storage Using the RSA PBKDF2 Standard
More information on why and how here:
首先:预先添加盐并不是安全问题。拥有每个密码的盐是一个很大的好处,并且将其与密码一起存储是完全可以的。
现在:只要您不将密码哈希从一个系统传输到另一个系统,并且后者不支持第一个系统的默认算法,那么根据定义就不会发生任何不好的情况。自 PHP 5.3 起,PHP 中就有内置算法,例如 Blowfish,保证可用。
First of all: Prepending the salt is not a security problem. Having a per-password salt is a big goodie, and it's perfectly OK to it being store alongside the pw.
Now: As long as you don't transport password hashes from one system to another, and the latter not supporting the default algorithm of the first, nothing bad will happen by definition. Since PHP 5.3 there are built-in algorithms in PHP such as Blowfish, that are guaranteed to be available.