?? password.java
字號(hào):
package com.jdon.simpleregister;
import java.sql.*;
/**
*
* 本程序?yàn)閹椭鯇W(xué)者了解Jsp/javabean 不建議商業(yè)用途 進(jìn)一步使用請(qǐng)參考Struts框架
*
* J道版權(quán)所有
* J道(http://www.jdon.com) Java的解決之道。
*
*/
public class Password {
//用戶Id
private String userid = null;
//原有密碼
private String password = null;
//新密碼
private String newpassword = null;
//新密碼校驗(yàn)
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;
}
/**
* 修改password表
* @return
* @throws java.lang.Exception
*/
public int update() throws Exception {
if (!isValid())
return Constants.FORM_ERROR;
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);
try {
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();
} catch (Exception ex) {
throw new Exception("Password.update()" + ex.getMessage());
} finally {
mysql.close();
mysql = null;
}
return Constants.OK;
}
/**
* 檢查輸入?yún)?shù)是否有效
* @return
*/
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;
}
/**
* 查詢passwordassit表
* @return
* @throws java.lang.Exception
*/
public boolean selectassit() throws Exception {
boolean valid = false;
String sql = "select * from passwordassit where userid= ?";
Mysql mysql = new Mysql(sql);
try {
mysql.setString(1, userid);
ResultSet rs = mysql.executeQuery();
if (rs != null && rs.next()) {
passwdtype = rs.getInt("passwdtype");
passwdanswer = rs.getString("passwdanswer");
valid = true;
}
} catch (Exception ex) {
throw new Exception("Password.selectassit()" + ex.getMessage());
} finally {
mysql.close();
mysql = null;
}
return valid;
}
/**
* 獲得丟失的密碼
* @return
* @throws java.lang.Exception
*/
public boolean getMypassword() throws Exception {
boolean valid = false;
ResultSet rs = null;
if (passwdanswer == null || passwdanswer.equals("") || passwdtype == 0)
return valid;
String sql =
"select * from passwordassit where userid=? and passwdtype = ? ";
Mysql mysql = new Mysql(sql);
try {
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;
}
}
} catch (Exception ex) {
throw new Exception("Password.getMypassword()" + ex.getMessage());
} finally {
mysql.close();
mysql = null;
}
return valid;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -