use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project best-cloud by shanzhaozhen.
the class AuthorizeApplicationTests method testPassword.
@Test
public void testPassword() throws IOException {
// PasswordEncoder passwordEncoder = new DelegatingPasswordEncoder();
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
boolean matches = passwordEncoder.matches("secret", "$2a$10$eX5hrXVr5/QWXAEt1BzRneb.RJIPOYNVj6NjTBLPfRJbQhx4jjPU2");
System.out.println(matches);
String encode = passwordEncoder.encode("123456");
System.out.println(encode);
}
use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project javaBook-src by huifer.
the class DefaultPasswordEncoderFactories method createDelegatingPasswordEncoder.
@SuppressWarnings("deprecation")
static PasswordEncoder createDelegatingPasswordEncoder() {
String encodingId = "bcrypt";
Map<String, PasswordEncoder> encoders = new HashMap<>();
encoders.put(encodingId, new BCryptPasswordEncoder());
encoders.put("ldap", new org.springframework.security.crypto.password.LdapShaPasswordEncoder());
encoders.put("MD4", new org.springframework.security.crypto.password.Md4PasswordEncoder());
encoders.put("MD5", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5"));
encoders.put("noop", org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance());
encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
encoders.put("scrypt", new SCryptPasswordEncoder());
encoders.put("SHA-1", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-1"));
encoders.put("SHA-256", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-256"));
encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder());
DelegatingPasswordEncoder delegatingPasswordEncoder = new DelegatingPasswordEncoder(encodingId, encoders);
delegatingPasswordEncoder.setDefaultPasswordEncoderForMatches(new BCryptPasswordEncoder(10));
return delegatingPasswordEncoder;
}
use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project ballcat by ballcat-projects.
the class PasswordUtils method createDelegatingPasswordEncoder.
/**
* 创建一个密码加密的代理,方便后续切换密码的加密算法
* @see PasswordEncoderFactories#createDelegatingPasswordEncoder()
* @return DelegatingPasswordEncoder
*/
@SuppressWarnings("deprecation")
private static PasswordEncoder createDelegatingPasswordEncoder() {
String encodingId = "bcrypt";
Map<String, PasswordEncoder> encoders = new HashMap<>(10);
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
encoders.put(encodingId, bCryptPasswordEncoder);
encoders.put("ldap", new org.springframework.security.crypto.password.LdapShaPasswordEncoder());
encoders.put("MD4", new org.springframework.security.crypto.password.Md4PasswordEncoder());
encoders.put("MD5", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5"));
encoders.put("noop", org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance());
encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
encoders.put("scrypt", new SCryptPasswordEncoder());
encoders.put("SHA-1", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-1"));
encoders.put("SHA-256", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-256"));
encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder());
encoders.put("argon2", new Argon2PasswordEncoder());
DelegatingPasswordEncoder delegatingPasswordEncoder = new DelegatingPasswordEncoder(encodingId, encoders);
// 设置默认的密码解析器,以便兼容历史版本的密码
delegatingPasswordEncoder.setDefaultPasswordEncoderForMatches(bCryptPasswordEncoder);
return delegatingPasswordEncoder;
}
use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project jakduk-api by JakduK.
the class PasswordEncoderTests method 스프링시큐리티_암호_인코딩.
@Test
public void 스프링시큐리티_암호_인코딩() {
String password = passwordEncoder.encode("1111");
Assert.assertFalse(passwordEncoder.matches("1112", password));
Assert.assertTrue(passwordEncoder.matches("1111", password));
DelegatingPasswordEncoder newPasswordEncoder = (DelegatingPasswordEncoder) PasswordEncoderFactories.createDelegatingPasswordEncoder();
newPasswordEncoder.setDefaultPasswordEncoderForMatches(new StandardPasswordEncoder());
System.out.println(newPasswordEncoder.encode("1111"));
Assert.assertTrue(newPasswordEncoder.matches("1111", password));
}
use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project jakduk-api by JakduK.
the class SecurityConfig method passwordEncoder.
@Bean
public PasswordEncoder passwordEncoder() {
DelegatingPasswordEncoder passwordEncoder = (DelegatingPasswordEncoder) PasswordEncoderFactories.createDelegatingPasswordEncoder();
passwordEncoder.setDefaultPasswordEncoderForMatches(new StandardPasswordEncoder());
return passwordEncoder;
}
Aggregations