本文整理汇总了Java中org.springframework.security.authentication.encoding.ShaPasswordEncoder.encodePassword方法的典型用法代码示例。如果您正苦于以下问题:Java ShaPasswordEncoder.encodePassword方法的具体用法?Java ShaPasswordEncoder.encodePassword怎么用?Java ShaPasswordEncoder.encodePassword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.authentication.encoding.ShaPasswordEncoder
的用法示例。
在下文中一共展示了ShaPasswordEncoder.encodePassword方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入方法依赖的package包/类
static public void main(String[] args ) {
if (args == null || args.length != 2) {
System.out.println("Please use: EssencePasswordEncoderSHA username password");
System.exit(1);
}
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
String hash = encoder.encodePassword(args[1], args[0]); // pwd, salt
System.out.println("Encoded password for " + args[0] + "/" + args[1] + " is: " + hash);
}
示例2: main
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入方法依赖的package包/类
public static void main(String[] args) {
ShaPasswordEncoder enc = new ShaPasswordEncoder(512);
enc.setIterations(1000);
enc.setEncodeHashAsBase64(true);
String encodedPass = enc.encodePassword("nesa", "nesa");
System.out.println(encodedPass);
System.out.println(enc.isPasswordValid(encodedPass, "nesa", "nesa"));
}
示例3: testSha
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入方法依赖的package包/类
@SuppressWarnings("unused")
static private void testSha() {
ShaPasswordEncoder encoder = new ShaPasswordEncoder();
String hash = encoder.encodePassword("test1", "test1"); // pwd, salt
System.out.println("test1:" + hash);
System.out.println("test2:" + encoder.encodePassword("test2", "test2"));
ShaPasswordEncoder encoder1 = new ShaPasswordEncoder(256);
String hash1 = encoder1.encodePassword("test1", "test1"); // pwd, salt
System.out.println("test1-256:" + hash1);
}
示例4: authenticate
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入方法依赖的package包/类
@Override
public User authenticate(String username, String password) {
// get user by username
User user = userDao.getByUsername(username);
if (user != null) {
ShaPasswordEncoder pwdEnc = new ShaPasswordEncoder();
String pwd = pwdEnc.encodePassword(password, user.getSalt());
if (pwd.equals(user.getPassword())) {
return user;
}
}
return null;
}
示例5: encode
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入方法依赖的package包/类
public static String encode(String password) {
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
String encodedPassword = encoder.encodePassword(password, null);
return encodedPassword;
}
示例6: create
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入方法依赖的package包/类
/**
* Create user detail with given username and encrypted given password.
*
* @param username username
* @param password plain text password
* @return user detail
*/
public static UserDetails create(String username, String password) {
final ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
final String hashedPassword = encoder.encodePassword(password, username);
return new UserDetailsImpl(username, hashedPassword);
}