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
Post a Comment