BCrypt helps keep passwords safe by turning them into secret codes. This way, even if someone sees the code, they can't easily guess the original password.
When you want to store user passwords safely in a database.
When building a login system that checks passwords securely.
When you want to protect user accounts from hackers.
When you need to compare a typed password with a stored secret code.
When you want to follow security best practices in your app.
B. encode method does not exist in BCryptPasswordEncoder
C. encoder is not initialized before use
D. Missing import statement for BCryptPasswordEncoder
Solution
Step 1: Check variable initialization
The variable encoder is declared but not assigned an instance before calling encode.
Step 2: Understand consequences
Using an uninitialized object causes a NullPointerException at runtime.
Final Answer:
encoder is not initialized before use -> Option C
Quick Check:
Uninitialized objects cause runtime errors [OK]
Hint: Always initialize objects before calling methods [OK]
Common Mistakes:
Forgetting to create new instance with 'new'
Assuming declaration equals initialization
Ignoring runtime NullPointerException
5. You want to store user passwords securely in your Spring Boot application. Which approach correctly uses BCryptPasswordEncoder to encode and verify passwords during login?
hard
A. Encode password on registration, store encoded; on login, use matches(rawPassword, storedEncodedPassword)
B. Store plain password; on login, encode input and compare with stored plain password
C. Encode password on registration, store encoded; on login, encode input and compare encoded strings directly
D. Encode password on registration, store encoded; on login, decode stored password and compare with input
Solution
Step 1: Understand secure password storage
Passwords must be encoded before storing; plain text storage is insecure.
Step 2: Verify password correctly on login
Use matches(rawPassword, storedEncodedPassword) to check if input matches stored hash without decoding.
Final Answer:
Encode password on registration, store encoded; on login, use matches(rawPassword, storedEncodedPassword) -> Option A
Quick Check:
Use matches() to verify passwords securely [OK]
Hint: Use matches() to check raw vs encoded passwords [OK]
Common Mistakes:
Comparing encoded strings directly (they differ each time)
Storing plain text passwords
Trying to decode encoded passwords (not possible)
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.