Database account and password encryption details and instances, account encryption details examples

Source: Internet
Author: User

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="" 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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.