如何使用Spring的StandardPasswordEncode?
StandardPasswordEncoder encoder = new StandardPasswordEncoder("secret");
String result = encoder.encode("myPassword");
assertTrue(encoder.matches("myPassword", result));
这一切都很清楚,但在数据库中,我只存储一个 VARCHAR 密码字段,存储由盐连接的哈希值?真有这么简单吗?
StandardPasswordEncoder encoder = new StandardPasswordEncoder("secret");
String result = encoder.encode("myPassword");
assertTrue(encoder.matches("myPassword", result));
This is all clear, but in database I just store a single VARCHAR password field storing hashed value concatenated by salt? Is it that simple?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在数据库中,您应该存储
endocer.encode
的返回值。这是错误的(或者可能只是写得不正确),正确的是:
hash(password+salt)
但不是相反
hash(password)+salt
!人们的意思是您不应该按原样存储密码(纯文本),但当然您可以将散列存储在文本表示形式中。 -- 人们谈论的问题是,如果任何人有权访问数据库,他不应该能够读取密码来使用它们。如果您认为将密码存储为哈希(例如 md5)不够安全,因为众所周知的 md5(明文表),那么可以在之前添加一个盐,并希望密码+盐不在该表中。
In the Database you should store the return value of
endocer.encode
.That is wrong (or may only not correct written), correct is:
hash(password+salt)
But NOT the other way around
hash(password)+salt
!The people mean that you should not store the password as it is (plain) but of course you can store the hash in a text representation. -- The problem that the people talk about is, that if anybody has access to the database he should not bean able to read the passwords to use them. If you think that storing passwords as hash (for example md5) is not secure enough, because of well known md5--cleartext tables, then one add a salt before, and hope that password+salt is not in that tables.