How can I hash passwords and salt them with Spring Security 3?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
easiest way, as documented:
HTH
Simplest seems to be Spring Security 3.1 assuming no constraints on the way hashing should be done:
Programmatic-ally you would do it as follows:
In your application-context.xml (defined in web.xml under
contextConfigLocation
) file define the bean (this example usesmd5
).Then Autowire the password encoder:
In your method or wherever you want to hash and salt.
The above call should return a salted hash (as a
String
).That should do it. I'm assuming you can figure out the jar's you'll need.
UPDATE
It should go without saying that using MD5 is not the best idea. Ideally you should use SHA-256 at least. This can be done with the
ShaPasswordEncoder
.Replace the MD5 bean config above with: