|
|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
package Base;
|
|
|
|
|
|
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
|
|
|
|
public class User {
|
|
|
|
|
private String email;
|
|
|
|
|
private String id;
|
|
|
|
|
@ -31,4 +34,22 @@ public class User {
|
|
|
|
|
}
|
|
|
|
|
return hasUpper && hasLower && hasDigit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String hash_pwd(String password){
|
|
|
|
|
try {
|
|
|
|
|
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
|
|
|
|
byte[] hashBytes = digest.digest(password.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
for (byte b : hashBytes) {
|
|
|
|
|
sb.append(String.format("%02x", b));
|
|
|
|
|
}
|
|
|
|
|
return sb.toString();
|
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
|
throw new RuntimeException("无法创建SHA-256实例", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean check_hash_pwd(String pwd,String hash_pwd){
|
|
|
|
|
return hash_pwd(pwd).equals(hash_pwd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|