MD5是生成账户验证码的好方法吗
当用户注册帐户时,他们会收到一封包含验证码的电子邮件,他们可以单击该电子邮件来验证其帐户。
这就是我生成验证码的方法。
md5(rand(0,1000)
使用下面的方法是一个错误的选择吗?它生成 0-1000 之间的随机数。由于只有 1000 个选项,并且它们的 MD5 哈希值是已知的,因此攻击者只需进行 1000 次尝试即可验证该帐户,而该帐户并不真正属于他们
When users register an account they get an email with a verification code that they can click to verify their accounts.
This is how I generate the verification code.
md5(rand(0,1000)
Is using the method below a bad choice? It generates a random number between 0-1000. Since there are only 1000 options, and their MD5 hashes are known, it should take an attacker just a 1000 trials to verify the account without it really belonging to them
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此线程 如何生成验证码/号码? 有一些不错的内容对此事的想法。哈希值、可逆哈希值、校验位......根据您的需求有很多选项。
This thread How to generate a verification code/number? has some good thoughts on the matter. Hashes, reversible hashes, check-digits... plenty of options depending on your needs.
rand(1,1000) 是 10 位熵。 MD5ing 它不添加任何内容。攻击者平均需要尝试 500 次才能验证帐户。再多的速率限制也无济于事,因为熟练的攻击者会租用或已经拥有一个僵尸网络,用于验证帐户。
谨慎行事,验证链接中包含 128 位熵。在 PHP 中 openssl_random_pseudo_bytes(16, true) 是获取加密强随机字节的可移植方法,但如果您在某些 Linux 发行版或 BSD 操作系统之一下托管,则读取 /dev/urandom 也是一个可接受的选择。
还要质疑验证帐户是否明智,许多人正是为此使用不可追踪的一次性电子邮件(并且您的黑名单永远不会更新)。
rand(1,1000) is 10 bits of entropy. MD5ing it adds none. On average it will take 500 tries for an attacker to verify an account. No amount of rate limiting will help you, as skilled attackers will rent or already own a botnet that will be used to validate the accounts.
Play it safe and have 128 bits of entropy in your verification links. In PHP openssl_random_pseudo_bytes(16, true) is the portable way to get cryptographically strong random bytes, but if you host under some Linux distribution or one of the BSD OS, reading /dev/urandom is also an acceptable choice.
Also question the wisdom of verifying accounts at all, many people use untraceable disposable emails exactly for that (and no your blacklist won't ever be up to date).
只要用攻击者无法知道的东西播种即可:
你可以疯狂到什么程度,没有限制
,但你明白了。
Just seed it with something the attacker could not know:
There is no limit at how crasy you could go
Way too much but you get the idea.