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

📄 password.java

📁 一个注册系统的源代码
💻 JAVA
字号:
package signup;

import java.sql.*;

/**
 *
 * 本程序为帮助初学者了解Jsp/javabean 不建议商业用途 进一步使用请参考Struts框架
 *
 * J道版权所有 
 * J道(http://www.jdon.com) Java的解决之道。
 *
 */



public class Password {
  private static BeansConstants CONST = BeansConstants.getInstance();
  private String userid = null;
  private String password = null;
  private String newpassword = null;
  private String newpassword2 = null;
  private String email = null;

  public void setUserid(String userid) {
    this.userid = userid;
  }

  public String getUserid() {
    return userid;
  }

  public void setNewpassword(String newpassword) {
    this.newpassword = newpassword;
  }

  public String getNewpassword() {
    return newpassword;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getPassword() {
    return password;
  }

  public String getEmail() {
    return email;
  }

  public void setNewpassword2(String newpassword2) {
    this.newpassword2 = newpassword2;
  }

  public String getNewpassword2() {
    return newpassword2;
  }

  private String passwdanswer = null;
  public void setPasswdanswer(String passwdanswer) {
    this.passwdanswer = passwdanswer;
  }

  public String getPasswdanswer() {
    if (passwdanswer != null) {
      return passwdanswer;
    }
    else {
      return "";
    }
  }

  private int passwdtype = 0;
  public void setPasswdtype(int passwdtype) {
    this.passwdtype = passwdtype;
  }

  public int getPasswdtype() {
    return passwdtype;
  }

  public int update() throws Exception {
    if (!isValid())
      return CONST.FORM_ERROR;
    try {
      String sql = "update password set password=PASSWORD(?) where userid=? and password=PASSWORD(?)";
      String assitsql = "update passwordassit set passwdtype=?,passwdanswer=?,oldpassword =? where userid=?";
      Mysql mysql = new Mysql(sql);
      mysql.setString(1, newpassword);
      mysql.setString(2, userid);
      mysql.setString(3, password);
      mysql.executeUpdate();

      mysql.prepareStatement(assitsql);
      mysql.setInt(1, passwdtype);
      mysql.setString(2, passwdanswer);
      mysql.setString(3, newpassword);
      mysql.setString(4, userid);
      mysql.executeUpdate();

      mysql.close();
      mysql = null;

    }
    catch (Exception ex) {
      throw new Exception("Password.update()" + ex.getMessage());
    }
    return CONST.OK;
  }

  public boolean isValid() {
    boolean valid = true;
    if (userid == null || userid.equals(""))
      valid = false;
    if (password == null || password.equals(""))
      valid = false;
    if (newpassword == null || newpassword.equals("") || newpassword2 == null ||
        newpassword2.equals("") || !newpassword.equals(newpassword2))
      valid = false;
    return valid;
  }

  public boolean selectassit() throws Exception {
    boolean valid = false;
    try {
      ResultSet rs = null;
      String sql = "select * from passwordassit where userid= ?";
      Mysql mysql = new Mysql(sql);
      mysql.setString(1, userid);
      rs = mysql.executeQuery();
      if (rs != null && rs.next()) {
        passwdtype = rs.getInt("passwdtype");
        passwdanswer = rs.getString("passwdanswer");
        valid = true;
      }
      mysql.close();
      mysql = null;
      return valid;
    }
    catch (Exception ex) {
      throw new Exception("Password.selectassit()" + ex.getMessage());
    }
  }

  public boolean getMypassword() throws Exception {
    boolean valid = false;
    ResultSet rs = null;
    if (passwdanswer == null || passwdanswer.equals("") || passwdtype == 0)
      return valid;
    try {
      String sql =
          "select * from passwordassit where userid=? and passwdtype = ? ";
      Mysql mysql = new Mysql(sql);
      mysql.setString(1, userid);
      mysql.setInt(2, passwdtype);
      rs = mysql.executeQuery();
      if (rs != null && rs.next()) {
        if (rs.getString("passwdanswer").equals(passwdanswer)) {
          password = rs.getString("oldpassword");
          valid = true;
        }
      }
      mysql.close();
      mysql = null;
    }
    catch (Exception ex) {
      throw new Exception("Password.getMypassword()" + ex.getMessage());
    }
    return valid;

  }

}

⌨️ 快捷键说明

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