📄 password_change_c.java
字号:
package project;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.sql.ResultSet;
import java.sql.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Password_change_C {
JFrame mainframe = null;
JPanel password_change = null;
public Password_change_C(JFrame mainframe,JPanel password_change) {
this.mainframe = mainframe;
this.password_change = password_change;
}
public int update_password(String old_text, String new_text1, String new_text2){
if(old_text.equals("")){
JOptionPane.showMessageDialog(this.mainframe,"请输入密码!","提示",JOptionPane.ERROR_MESSAGE);
return 0;
}
if(new_text1.equals("")){
JOptionPane.showMessageDialog(this.mainframe,"请输入新的密码!","提示",JOptionPane.ERROR_MESSAGE);
return 1;
}
if(new_text2.equals("")){
JOptionPane.showMessageDialog(this.mainframe,"请再输入一次新的密码!","提示",JOptionPane.ERROR_MESSAGE);
return 2;
}
if(!new_text1.equals(new_text2)){
JOptionPane.showMessageDialog(this.mainframe,"新密码输入不一致, 请再输入一次新的密码!","提示",JOptionPane.ERROR_MESSAGE);
return 3;
}
DataBase db = new DataBase();
Frame1 temp = (Frame1)this.mainframe;
String sql = "select * from login_table where loginName='"+temp.get_userName()+"' and password='"+old_text+"'";
try {
ResultSet rs = db.executeQuery(sql);
if (!rs.next()) {
JOptionPane.showMessageDialog(this.mainframe,"旧密码输入错误, 请再输入一次!","提示",JOptionPane.ERROR_MESSAGE);
rs.close();
return 4;
}else{
String update_sql ="update login_table set password='"+new_text1+"' where loginName='"+temp.get_userName()+"'";
int res = db.executeUpdate(update_sql);
if(res > 0){
JOptionPane.showMessageDialog(this.mainframe,"密码更新成功,下次登陆请使用新密码!","提示",JOptionPane.INFORMATION_MESSAGE);
db.close();
return 5;
}else{
JOptionPane.showMessageDialog(this.mainframe,"密码更新失败!","提示",JOptionPane.ERROR_MESSAGE);
db.close();
return 6;
}
}
}
catch (SQLException ex) {
ex.printStackTrace();
db.close();
JOptionPane.showMessageDialog(this.mainframe,"数据库错误!","提示",JOptionPane.ERROR_MESSAGE);
return -1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -