Password encoding and decoding using Spring Security, Spring Boot and MongoDB -


i use mentions software stack above , need encrypt password before save database. need decrypt password because when change password needs give in old password , new onw twice , need check old password. have searched lot still not sure right way this. have found link encrypting there other hints this? not sure if maybe mongodb provides protect passwords.

first read steven carlson´s answer password hashing.

the thing spring security you. spring security 3.2 introduced new org.springframework.security.crypto.password.passwordencoder interface , implementations: bcryptpasswordencoder, standardpasswordencoder (and nooppasswordencoder).

important: not confuse org.springframework.security.crypto.password.passwordencoder old deprecated org.springframework.security.authentication.encoding.passwordencoder

the interface (and therefore implementations) has 2 methods need:

  • public string encode(charsequence rawpassword)
  • public boolean matches(charsequence rawpassword, string encodedpassword)

i recommend use org.springframework.security.crypto.bcrypt.bcryptpasswordencoder. bcryptpasswordencoder (in contrast standardpasswordencoder) use salt different each password (but not global 1 standardpasswordencoder). when encode raw password (public string encode(charsequence rawpassword)) returned encoded password not encoded password, contains meta information used hash-algorithm, used salt , of course encoded password.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -