Database account and password encryption details and instances, account encryption details examples
Database account and password encryption details and examples
In the database, the password of the database account is often encrypted. However, when UserService is used to encrypt the password, spring security also needs to be configured synchronously, because the encryption method verified in spring security is configured separately. As follows:
<authentication-manager> <authentication-provider user-service-ref="userDetailService"> <password-encoder ref="passwordEncoder" /> </authentication-provider></authentication-manager><beans:bean class="com.sapphire.security.MyPasswordEncoder" id="passwordEncoder"> <beans:constructor-arg value="md5"></beans:constructor-arg></beans:bean>
As shown in the preceding configuration file, passwordEncoder is the place where spring security encrypts and verifies the account.
After interception, spring security first searches for the user and finds the corresponding user through the User-Defined userDetailService. Then, the Framework verifies the password matching.
After obtaining the user from userDetailService, it enters DaoAuthenticationProvider, which is defined in the framework and then jumps into the authenticate Method.
This method performs two checks:
* PreAuthenticationChecks: checks whether the user has expired or not. The called method is defined in userDetail. * AdditionalAuthenticationChecks: This is the process of verifying the user name and password.
While PasswordEncoder is the bean injected into our xml, so we call passwordEncoder we have done by ourselves.
public class MyPasswordEncoder extends MessageDigestPasswordEncoder { public MyPasswordEncoder(String algorithm) { super(algorithm); } @Override public boolean isPasswordValid(String encPass, String rawPass, Object salt) { return encPass.equals(DigestUtils.md5DigestAsHex(rawPass.getBytes())); }}
This is a simple version I implemented for it. It calls the built-in encryption algorithm of spring, which is very simple. Of course, you can also use complicated encryption methods. This depends on your own.
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!