SPRING in ACTION 4th Release Notes-Chapter Nineth Securing Web applications-004-Password Encryption passwordencoder

Source: Internet
Author: User

One

1.focusing on the authentication query, you can see that user passwords is expected to being stored in The database. the only problem with this is if the passwords be stored in plain text, they ' re subject to the prying eyes of a hacker. If you encode the password in the database and then authentication'll fail because it won ' t match the plain text password submitted by the user.

1 @Override2 protected voidConfigure (Authenticationmanagerbuilder auth)3 throwsException {4 Auth5 . Jdbcauthentication ()6 . DataSource (DataSource)7 . Usersbyusernamequery (8"Select username, password, true" +9"From Spitter where username=?")Ten . Authoritiesbyusernamequery ( One"Select Username, ' Role_user ' from Spitter where username=?") A. Passwordencoder (NewStandardpasswordencoder ("53cr3t")); -}

the Passwordencoder method receives the implementation of the Passwordencoder interface as a parameter, and spring provides 3 implementations: Bcryptpasswordencoder, Nooppasswordencoder, and Standardpasswordencoder

The interface code is as follows:

 Public Interface Passwordencoder {    String encode (charsequence rawpassword);     Boolean matches (charsequence Rawpassword, String encodedpassword);}

it ' s important to understand the password in the database is never decoded. Instead, the password, the user enters at login is encoded using the same algorithm and are then compared with The encoded password in the database. That comparison was performed in the Passwordencoder ' s matches () method.

SPRING in ACTION 4th Release Notes-Chapter Nineth Securing Web applications-004-Password Encryption passwordencoder

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: info-contact@alibabacloud.com 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.