In spring security, configure a salt-encrypted service with a password of MD5:
Private Md5passwordencoder encoder; Spring Security MD5
Public Md5passwordencoder Getencoder () {
Return encoder;
}
@Resource
public void Setencoder (Md5passwordencoder encoder) {
This.encoder = encoder;
}
@Override
public void AddUser (user user) {
Assign the encrypted password to user password
Salt is user name
User.setpassword (Encoder.encodepassword (User.getpassword (), User.getname ());
Userdao.adduser (user);
}
Jt.executeupdate (New Stringsql (
"Insertinto vdb_users (Userid,password) VALUES (?,?)",
Uid,new Md5passwordencoder (). Encodepassword (up, UID)));
New Md5passwordencoder (). Encodepassword (Up,uid)
The Md5passwordencoder here is the spring-brought MD5 encryption class, where the first parameter up is a password and the UID is a salt value
Applicationcontext-security.xml:
<!--Configure the authentication manager to achieve the user authentication of the portal, the main implementation of the Userdetailsservice interface can-
<authentication-manageralias= "AuthenticationManager" >
<!--
<authentication-providerref= "Principalprovider" ></authentication-provider>
-
<!--with custom Userdetailservice--
<authentication-provideruser-service-ref= "UserService" >
<!--encrypt your password with MD5-
<password-encoderhash= "MD5" >
<!--salt, according to user name as salt--
<salt-sourceuser-property= "Name"/>
</password-encoder>
<!--
<security:user-service>
<security:username= "Admin"
Password= "2L232F297A57A5A748394A0E4A80LFC3"
authorities= "Role_user"/>
<security:username= "User" password= "user"
authorities= "Role_user"/>
</security:user-service>
-
<!--default Test.user table ... -
<!--
Salt encryption with password MD5 configured in spring security