final commit

main^2
Arno 2 months ago committed by Gitea
parent 9ee1a82f59
commit 1b164c09e4

@ -26,7 +26,8 @@ Math_learning
    |——Exam_service.java  考试服务类
    |——Deal_file.java  可选功能:保存试卷为文件
  |——View  前端类包
    |——MainFrame.java  前端界面
  |——Math_learning_app.java  主类
|——doc  说明文档
  |——README.md
@ -40,11 +41,11 @@ Math_learning
4. 其他邮箱配置方法具体见官方说明。
## 用户信息
用户信息保存在本地,用户/用户信息.txt(运行时会产生)
用户信息保存在本地,用户/用户信息.txt(运行时会产生),密码已加密。
## 运行环境
可执行文件Math_Learning.jar依赖已经打包
Windows  UTF-8编码  
本软件使用java 23编译请使用java 17及以上版本运行  UTF-8编码  
---
软件2302

@ -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);
}
}

@ -41,7 +41,7 @@ public class User_service {
return "密码长6-20位至少包含大小写字母和数字";
}
User new_one=new User(email);
new_one.set_password(pwd);
new_one.set_password(User.hash_pwd(pwd));
new_one.set_id(id);
if (find_user_i(id)!=null){
return "用户名重复";
@ -63,7 +63,7 @@ public class User_service {
if (u==null){
return "请先注册";
}
if (u.get_password().equals(pwd)){
if (User.check_hash_pwd(pwd,u.get_password())){
return "登陆成功";
}
return "密码有误";
@ -74,7 +74,7 @@ public class User_service {
if (user == null) {
return "用户不存在";
}
if (!user.get_password().equals(oldPassword)) {
if (!User.check_hash_pwd(oldPassword,user.get_password())) {
return "原密码不正确";
}
if (oldPassword.equals(newPassword)){

Loading…
Cancel
Save