cn.crazywalker.fsf.security.PasswordUtils Maven / Gradle / Ivy
The newest version!
package cn.crazywalker.fsf.security;
import cn.crazywalker.fsf.common.util.StringUtils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
/**
* 密码工具类(加密、匹配等)
* @author CrazyWalker
* @since 周日, 04/16 2023 20:51 GMT+8
*/
public class PasswordUtils {
private static final PasswordEncoder PASSWORD_ENCODER = new BCryptPasswordEncoder();
private PasswordUtils() {}
public static String encode(String source) {
if (!StringUtils.hasLength(source)) {
throw new IllegalPasswordException("Source password can not be empty.");
}
return PASSWORD_ENCODER.encode(source);
}
public static boolean matches(String rawPassword, String encodePassword) {
if (!StringUtils.hasLength(rawPassword) || !StringUtils.hasLength(encodePassword)) {
return false;
}
return PASSWORD_ENCODER.matches(rawPassword, encodePassword);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy