0
0
Spring Bootframework~10 mins

Password encoding with BCrypt in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a BCrypt password encoder bean.

Spring Boot
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Configuration
public class SecurityConfig {

    @Bean
    public BCryptPasswordEncoder passwordEncoder() {
        return new [1]();
    }
}
Drag options to blanks, or click blank then click option'
ABCryptPasswordEncoder
BPasswordEncoder
CEncoder
DBCryptEncoder
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic interface name instead of the concrete BCryptPasswordEncoder class.
Misspelling the class name.
2fill in blank
medium

Complete the code to encode a raw password using BCryptPasswordEncoder.

Spring Boot
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String rawPassword = "mySecret123";
String encodedPassword = encoder.[1](rawPassword);
Drag options to blanks, or click blank then click option'
Ahash
Bencrypt
Cencode
Ddigest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'hash' or 'encrypt' which are not method names in this class.
Confusing encoding with encryption.
3fill in blank
hard

Fix the error in the code to verify a raw password against an encoded password.

Spring Boot
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String rawPassword = "password123";
String encodedPassword = "$2a$10$7QJH1...";
boolean matches = encoder.[1](rawPassword, encodedPassword);
Drag options to blanks, or click blank then click option'
Acompare
Bverify
Ccheck
Dmatches
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like 'check' or 'verify'.
Swapping the order of parameters.
4fill in blank
hard

Fill both blanks to correctly verify a password using BCryptPasswordEncoder.

Spring Boot
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
boolean isValid = encoder.[1]([2], encodedPassword);
Drag options to blanks, or click blank then click option'
Amatches
BrawPassword
CencodedPassword
Dencode
Attempts:
3 left
💡 Hint
Common Mistakes
Using the encoded password as the first argument.
Using 'encode' instead of 'matches' method.
5fill in blank
hard

Fill all three blanks to create a Spring service that encodes a password and verifies it.

Spring Boot
import org.springframework.stereotype.Service;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Service
public class PasswordService {

    private final BCryptPasswordEncoder encoder = new [1]();

    public String encodePassword(String [2]) {
        return encoder.[3]([2]);
    }

    public boolean verifyPassword(String rawPassword, String encodedPassword) {
        return encoder.matches(rawPassword, encodedPassword);
    }
}
Drag options to blanks, or click blank then click option'
ABCryptPasswordEncoder
Bpassword
Cencode
DPasswordEncoder
Attempts:
3 left
💡 Hint
Common Mistakes
Using interface name instead of concrete class for encoder.
Using wrong parameter name in method.
Calling a non-existent method instead of 'encode'.