在 ASP.NET MVC 3 中加密密码
我正在尝试在 ASP.NET MVC3 中创建自定义会员系统。
我知道有许多免费和开源提供商,但我这样做是为了了解更多信息。我的问题是关于加密密码。
您建议我使用哪种算法:SHA1
、SHA256
、MD5
、BCrypt
还是其他算法?另外,您建议采用哪种方式创建密码盐?
I'm trying to create a custom membership system in ASP.NET MVC3
.
I know there are many free and open source providers, but I'm doing this to learn more. My question is about encrypting passwords.
Which algorithm do you suggest I use: SHA1
, SHA256
, MD5
, BCrypt
, or something else? Also, which way do you suggest to create a password salt?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
BCrypt 如果您需要真正强大的哈希值。就生成盐而言,您可以使用 RNGCryptoServiceProvider 类。您可以查看以下一篇文章。只需用 BCrypt 替换那里使用的 SHA1 算法即可。
BCrypt if you need really strong hash. As far as generating the salt is concerned, you could use the RNGCryptoServiceProvider class. Here's an article that you may checkout. Just replace the SHA1 algorithm used there with BCrypt.
大多数这些算法都是散列算法,它们不加密,而是创建散列(校验和),通常这是存储密码的最佳方式,除非您有充分的理由想要一种恢复密码的方法(而且我不这样做)我认为这有很多原因)。
我通常使用 sha256。关于盐,随机 6 个或更多字符的字符串就足够了。但盐可以是任何东西,这取决于你的想象力如何生成它。
Most of those algorithms are hashing algorithms, they don't encrypt they create a hash (checksum) and usually this is the best way to store passwords, unless you have a really good reason to want a way to restore passwords (and I don't think there are many reasons for that).
I tipically use sha256. About the salt, a random 6 or more characters string is enough. But the salt can be anything, it depends on your imagination how to generate it.