30 lines
662 B
Java
30 lines
662 B
Java
package com.tailbet.util;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.crypto.digest.DigestUtil;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
/**
|
|
* 密码工具类
|
|
*/
|
|
@Component
|
|
public class PasswordUtil {
|
|
|
|
/**
|
|
* BCrypt加密
|
|
*/
|
|
public String encode(String rawPassword) {
|
|
return DigestUtil.bcrypt(rawPassword);
|
|
}
|
|
|
|
/**
|
|
* BCrypt校验
|
|
*/
|
|
public boolean matches(String rawPassword, String encodedPassword) {
|
|
if (StrUtil.isBlank(rawPassword) || StrUtil.isBlank(encodedPassword)) {
|
|
return false;
|
|
}
|
|
return DigestUtil.bcryptCheck(rawPassword, encodedPassword);
|
|
}
|
|
}
|