BAEL-1489: Applying Baeldung code styles and cleaning up
This commit is contained in:
parent
62d9eed9fd
commit
e61b157057
@ -0,0 +1,33 @@
|
||||
package com.baeldung.passwordstorage;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Configuration
|
||||
public class BaeldungPasswordEncoderSetup {
|
||||
|
||||
@Bean
|
||||
public PasswordEncoder passwordEncoder() {
|
||||
// set up the list of supported encoders and their prefixes
|
||||
String encodingId = "rot13";
|
||||
Map<String, PasswordEncoder> encoders = new HashMap<>();
|
||||
encoders.put(encodingId, new Rot13PasswordEncoder());
|
||||
encoders.put("scrypt", new SCryptPasswordEncoder());
|
||||
encoders.put("bcrypt", new BCryptPasswordEncoder());
|
||||
|
||||
// get an instance of the DelegatingPasswordEncoder, set up to use our instance as default encoder
|
||||
DelegatingPasswordEncoder delegatingPasswordEncoder = new DelegatingPasswordEncoder(encodingId, encoders);
|
||||
|
||||
// configure our instance as default encoder for actual matching
|
||||
delegatingPasswordEncoder.setDefaultPasswordEncoderForMatches(encoders.get(encodingId));
|
||||
|
||||
return delegatingPasswordEncoder;
|
||||
}
|
||||
}
|
@ -12,7 +12,9 @@ public class Rot13PasswordEncoder implements PasswordEncoder {
|
||||
@Override
|
||||
public String encode(CharSequence rawPassword) {
|
||||
StringBuffer result = new StringBuffer(rawPassword.length());
|
||||
rawPassword.chars().forEach(charCode -> {
|
||||
rawPassword
|
||||
.chars()
|
||||
.forEach(charCode -> {
|
||||
if (charCode >= 65 && charCode <= 77 || charCode >= 97 && charCode <= 109) {
|
||||
result.append(Character.toChars(charCode + 13));
|
||||
} else if (charCode >= 78 && charCode <= 90 || charCode >= 110 && charCode <= 133) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user