Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is BCrypt in the context of password encoding?
BCrypt is a password hashing function designed to securely encode passwords by adding a salt and using multiple rounds of hashing to protect against brute-force attacks.
Click to reveal answer
beginner
How do you create a BCrypt password encoder in Spring Boot?
You create a BCrypt password encoder by defining a bean like this:
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
Click to reveal answer
intermediate
Why is it important to use a salt in password encoding?
A salt adds random data to the password before hashing, making each hash unique even if two users have the same password. This prevents attackers from using precomputed tables to crack passwords.
Click to reveal answer
beginner
How do you verify a raw password against a BCrypt encoded password in Spring Boot?
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)