dwr实现找回密码的功能
2009-09-17 00:00:00 来源:WEB开发网需求:用户根据自己注册的账号、邮箱实现可以找回密码的功能。
实现:就是根据正确的账号、邮箱,实现自动发邮件的功能。
下面看我的实现过程:
先看两个配置文件:
1.db.properties
Java代码
database.driver_class=oracle.jdbc.driver.OracleDriver
database.url=jdbc:oracle:thin:@webnet:1521:orcl
database.username=baseext
database.password=11
2.mail.properties
Java代码
mail.account=wenbinandy@gmail.com
mail.password=*******
mail.host=smtp.gmail.com
DAO层UnionUsersDAO查询数据库得到密码
Java代码
public String getPassword(String account,String email) throws Exception{
InputStream inputStream =this.getClass().getClassLoader().getResourceAsStream("db.properties");
Properties p = new Properties();
try {
p.load(inputStream);
inputStream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
String drivers = p.getProperty("database.driver_class");
String url = p.getProperty("database.url");
String user = p.getProperty("database.username");
String password = p.getProperty("database.password");
Connection conn = null;
Statement stat = null;
ResultSet rs = null;
String passWord = "";
try{
Class.forName(drivers);
conn = DriverManager.getConnection(url, user, password);
stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String sql = "select c_password from union_users where c_account='"+account+"' and c_email ='"+email+"'";
rs = stat.executeQuery(sql);
while(rs.next()){
passWord = rs.getString(1);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs!=null){
rs.close();
rs=null;
}
if(stat!=null){
stat.close();
stat=null;
}
if(conn!=null){
conn.close();
conn=null;
}
}
return passWord;
}
更多精彩
赞助商链接