Performance: Password encoding with BCrypt
This affects the server-side processing time during user authentication and registration, impacting response time and user experience.
Jump into concepts and practice - no test required
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); String hashed = encoder.encode(password);
String hashed = DigestUtils.md5Hex(password);
| Pattern | CPU Load | Response Time Impact | Security Level | Verdict |
|---|---|---|---|---|
| MD5 hashing | Low | Minimal | Low (insecure) | [X] Bad |
| BCrypt hashing (default strength) | Medium | Moderate | High (secure) | [OK] Good |
BCryptPasswordEncoder in Spring Boot?BCryptPasswordEncoder instance in Spring Boot?new keyword followed by the constructor.new BCryptPasswordEncoder(); to create an instance.matches method?BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String rawPassword = "mypassword";
String encodedPassword = encoder.encode(rawPassword);
boolean result = encoder.matches("mypassword", encodedPassword);
System.out.println(result);encode method creates a hashed password. The matches method checks if the raw password matches the encoded hash.matches compares the same raw password with the encoded one, so it returns true.BCryptPasswordEncoder encoder;
String encoded = encoder.encode("secret");encoder is declared but not assigned an instance before calling encode.BCryptPasswordEncoder to encode and verify passwords during login?matches(rawPassword, storedEncodedPassword) to check if input matches stored hash without decoding.