mirror of
https://github.com/FatttSnake/ClassroomInteraction.git
synced 2026-04-06 05:41:26 +08:00
Added changePasswd()
This commit is contained in:
@@ -191,6 +191,10 @@ public class DatabaseHelper {
|
|||||||
return StudentOA.checkPasswd(stuID, passwd);
|
return StudentOA.checkPasswd(stuID, passwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean changePasswdInStudent(long stuID, String passwd) throws NoConfigException, SQLException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
|
return StudentOA.changePasswd(stuID, passwd);
|
||||||
|
}
|
||||||
|
|
||||||
public static Student insertIntoStudent(long stuID, String stuName, Gender gender, long classID, String passwd) throws NoConfigException, SQLException, InsertException, AlreadyExistsException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
|
public static Student insertIntoStudent(long stuID, String stuName, Gender gender, long classID, String passwd) throws NoConfigException, SQLException, InsertException, AlreadyExistsException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
return StudentOA.insert(stuID, stuName, gender, classID, passwd);
|
return StudentOA.insert(stuID, stuName, gender, classID, passwd);
|
||||||
}
|
}
|
||||||
@@ -215,6 +219,10 @@ public class DatabaseHelper {
|
|||||||
return TeacherOA.checkPasswd(tchID, passwd);
|
return TeacherOA.checkPasswd(tchID, passwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean changePasswdInTeacher(long tchID, String passwd) throws NoConfigException, SQLException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
|
return TeacherOA.changePasswd(tchID, passwd);
|
||||||
|
}
|
||||||
|
|
||||||
public static Teacher insertIntoTeacher(long tchID, String tchName, Gender gender, int facID, String passwd) throws NoConfigException, SQLException, InsertException, AlreadyExistsException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
|
public static Teacher insertIntoTeacher(long tchID, String tchName, Gender gender, int facID, String passwd) throws NoConfigException, SQLException, InsertException, AlreadyExistsException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
return TeacherOA.insert(tchID, tchName, gender, facID, passwd);
|
return TeacherOA.insert(tchID, tchName, gender, facID, passwd);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,25 @@ public class StudentOA {
|
|||||||
return pbkdf2Util.authenticate(passwd, student.getPassword(), student.getSalt());
|
return pbkdf2Util.authenticate(passwd, student.getPassword(), student.getSalt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean changePasswd(long stuID, String passwd) throws NoConfigException, SQLException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
|
Student student = select(stuID);
|
||||||
|
if (student == null) {
|
||||||
|
throw new DependenciesNotFoundException();
|
||||||
|
}
|
||||||
|
PBKDF2Util pbkdf2Util = new PBKDF2Util();
|
||||||
|
String salt = pbkdf2Util.generateSalt();
|
||||||
|
String encryptedPassword = pbkdf2Util.getEncryptedPassword(passwd, salt);
|
||||||
|
String sql = "UPDATE student SET passwd=?,salt=? WHERE stuID=?";
|
||||||
|
try (Connection connection = PoolHelper.getConnection()) {
|
||||||
|
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||||
|
preparedStatement.setString(1, encryptedPassword);
|
||||||
|
preparedStatement.setString(2, salt);
|
||||||
|
preparedStatement.setLong(3, stuID);
|
||||||
|
return preparedStatement.executeUpdate() == 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Student insert(long stuID, String stuName, Gender gender, long classID, String passwd) throws NoConfigException, SQLException, AlreadyExistsException, DependenciesNotFoundException, InsertException, NoSuchAlgorithmException, InvalidKeySpecException {
|
public static Student insert(long stuID, String stuName, Gender gender, long classID, String passwd) throws NoConfigException, SQLException, AlreadyExistsException, DependenciesNotFoundException, InsertException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
if (isExists(stuID)) throw new AlreadyExistsException();
|
if (isExists(stuID)) throw new AlreadyExistsException();
|
||||||
if (!ClassOA.isExists(classID)) throw new DependenciesNotFoundException();
|
if (!ClassOA.isExists(classID)) throw new DependenciesNotFoundException();
|
||||||
|
|||||||
@@ -52,6 +52,25 @@ public class TeacherOA {
|
|||||||
return pbkdf2Util.authenticate(passwd, teacher.getPassword(), teacher.getSalt());
|
return pbkdf2Util.authenticate(passwd, teacher.getPassword(), teacher.getSalt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean changePasswd(long tchID, String passwd) throws NoConfigException, SQLException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
|
Teacher teacher = select(tchID);
|
||||||
|
if (teacher == null) {
|
||||||
|
throw new DependenciesNotFoundException();
|
||||||
|
}
|
||||||
|
PBKDF2Util pbkdf2Util = new PBKDF2Util();
|
||||||
|
String salt = pbkdf2Util.generateSalt();
|
||||||
|
String encryptedPassword = pbkdf2Util.getEncryptedPassword(passwd, salt);
|
||||||
|
String sql = "UPDATE teacher SET passwd=?,salt=? WHERE tchID=?";
|
||||||
|
try (Connection connection = PoolHelper.getConnection()) {
|
||||||
|
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||||
|
preparedStatement.setString(1, encryptedPassword);
|
||||||
|
preparedStatement.setString(2, salt);
|
||||||
|
preparedStatement.setLong(3, tchID);
|
||||||
|
return preparedStatement.executeUpdate() == 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Teacher insert(long tchID, String tchName, Gender gender, int facID, String passwd) throws NoConfigException, SQLException, AlreadyExistsException, DependenciesNotFoundException, InsertException, NoSuchAlgorithmException, InvalidKeySpecException {
|
public static Teacher insert(long tchID, String tchName, Gender gender, int facID, String passwd) throws NoConfigException, SQLException, AlreadyExistsException, DependenciesNotFoundException, InsertException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
if (isExists(tchID)) throw new AlreadyExistsException();
|
if (isExists(tchID)) throw new AlreadyExistsException();
|
||||||
if (!FacultyOA.isExists(facID)) throw new DependenciesNotFoundException();
|
if (!FacultyOA.isExists(facID)) throw new DependenciesNotFoundException();
|
||||||
|
|||||||
Reference in New Issue
Block a user