⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chgpwd.java

📁 在管理员表中初始插入数据 usn: admin, pwd: 21232F297A57A5A743894A0E4A801FC3 初始用户账号/密码: admin (密码为 md5 加密) SRC
💻 JAVA
字号:
import java.awt.BorderLayout;
import java.awt.Frame;
import java.sql.*;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ChgPwd extends JDialog implements ActionListener {
    JPanel panel1 = new JPanel();
    BorderLayout borderLayout1 = new BorderLayout();
    JLabel jLabel1 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JLabel jLabel4 = new JLabel();
    JPasswordField t3 = new JPasswordField();
    JPasswordField t2 = new JPasswordField();
    JPasswordField t1 = new JPasswordField();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();

    public ChgPwd(Frame owner, String title, boolean modal) {
        super(owner, title, modal);
    	Gload.checkLogin(this);
        try {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jbInit();
            //pack();
            this.jTextField1.setText(Gload.usn);
            this.setBounds((Gload.de.width - 320)/2, (Gload.de.height-150)/2, 320, 150);
            this.setResizable(false);
            this.setResizable(false);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public ChgPwd() {
        this(new Frame(), "ChgPwd", false);
    }

    private void jbInit() throws Exception {
        panel1.setLayout(null);
        jLabel1.setText("用户名:");
        jLabel1.setBounds(new Rectangle(6, 7, 45, 24));
        jTextField1.setEditable(false);
        jTextField1.setText("jTextField1");
        jTextField1.setBounds(new Rectangle(49, 10, 141, 20));
        jLabel2.setText("旧密码:");
        jLabel2.setBounds(new Rectangle(3, 34, 43, 21));
        jLabel3.setText("新密码:");
        jLabel3.setBounds(new Rectangle(5, 62, 43, 19));
        jLabel4.setText("确 认:");
        jLabel4.setBounds(new Rectangle(3, 85, 43, 23));
        t3.setBounds(new Rectangle(48, 90, 145, 18));
        t2.setText("");
        t2.setBounds(new Rectangle(47, 62, 145, 21));
        t1.setText("");
        t1.setBounds(new Rectangle(47, 36, 145, 22));
        jButton1.setBounds(new Rectangle(225, 84, 70, 25));
        jButton1.setText("取 消");
        jButton1.addActionListener(this);
        jButton2.setBounds(new Rectangle(224, 53, 70, 24));
        jButton2.setText("确 定");
        jButton2.addActionListener(this);
        getContentPane().add(panel1);
        panel1.add(jLabel1);
        panel1.add(jTextField1);
        panel1.add(jLabel2);
        panel1.add(jLabel3);
        panel1.add(t3);
        panel1.add(t1);
        panel1.add(t2);
        panel1.add(jLabel4);
        panel1.add(jButton1);
        panel1.add(jButton2);
    }

    public void actionPerformed(ActionEvent e) {
        Object o = e.getSource();
        if (o.equals(this.jButton1)) {
            this.dispose();
        } else if (o.equals(this.jButton2)) {
        	this.jButton2_actionPerformed(e);
        }
    }
    
    public void jButton2_actionPerformed(ActionEvent e) {
        String s1, s2, s3;
        s1 = Gload.getText(t1);
        s2 = t2.getText().trim();
        s3 = t3.getText().trim();
        if (s1.equals("")) {
            Gload.MSG(this, "请填写旧密码!");
            t1.grabFocus();
            return;
        }
        if (s2.equals("")) {
            Gload.MSG(this, "请填写新密码!");
            t2.grabFocus();
            return;
        }
        if (s3.equals("")) {
            Gload.MSG(this, "请填写确认密码!");
            t3.grabFocus();
            return;
        }
        if (!s2.equals(s3)) {
            Gload.MSG(this, "两次密码输入不一致");
            t3.grabFocus();
            return;
        }
        MD5 md5 = new MD5();
        s1 = md5.hashOfStr(s1);
        Conn.ConnDB();
        ResultSet rs = Conn.query("select * from 管理员 where usn='" + Gload.usn + "' and pwd='" + s1 + "'");

        try {
            if (rs.next()) {
                rs.close();
                Conn.exec("update 管理员 set pwd='" + md5.hashOfStr(s2) + "' where usn='" + Gload.usn + "'");
                Gload.MSG(this, "修改密码成功!");
            } else {
                rs.close();
                Gload.MSG(this, "旧密码不正确!");
            }
        } catch (SQLException e2) {
            e2.printStackTrace();
        } finally {
            Conn.close();
        }
        this.dispose();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -