bcrypt
- Performs one-way encrypted hashing
- Adds a random salt to the password for additaional protection
- Includes support to defeat brute force attacks
Spring Security Password Storage
- In Spring Security 5, passwords are stored using a specific format.
- {bcrypt}encodedPassword
- Password column must be at least 68 chars wide:
- {bcrypt} - 8 chars
- encodedPassword - 60 chars
Modify DDL for Password Field
1 | CREATE TABLE `users` ( |
Spring Security Login Porcess
User enters plaintext password and go through Spring Security Filters
- Retrieve password from db for the user
- Read the encoding algorithm id(bcrypt etc)
- For case of bcrypt, encrypt plaintext password from login form(using salt from db password)
- Compare encrypted password from login form WITH encrypted password from db
- If there is a match, login successful
- If no match, login NOT successful
Note: The password from db is NEVER decrypted, because bcrypt is a one-way encryption algorithm