diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/Password.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/Password.class new file mode 100644 index 0000000..1fb6897 Binary files /dev/null and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/Password.class differ diff --git a/project2/src/main/java/cyou/chenx221/pojo/Password.java b/project2/src/main/java/cyou/chenx221/pojo/Password.java new file mode 100644 index 0000000..d098d94 --- /dev/null +++ b/project2/src/main/java/cyou/chenx221/pojo/Password.java @@ -0,0 +1,36 @@ +package cyou.chenx221.pojo; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class Password { + private String password; + private String encryptedPassword; + + public Password() { + } + + public Password(String password) throws NoSuchAlgorithmException { + encryptedPassword = encryptPassword(password); + } + + private String encryptPassword(String password) throws NoSuchAlgorithmException { + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + byte[] hash = digest.digest(password.getBytes()); + + StringBuilder hexString = new StringBuilder(); + for (byte b : hash) { + String hex = Integer.toHexString(0xff & b); + if (hex.length() == 1) { + hexString.append('0'); + } + hexString.append(hex); + } + return hexString.toString(); + } + + public String getEncryptedPassword() { + return encryptedPassword; + } + +}