String password1=request.getParameter("password1");
password1=getString(password1);
String password2=request.getParameter("password2");
password2=getString(password2);
Statement sql=null;
ResultSet rs=null;
boolean modify=false;
boolean ifEquals=false;
ifEquals=(password1.equals(password2))&&(password1.length()<=20)&&(password1.length()>=6);
if(ifEquals==true)
{try
{ Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:shop","root","123456");
sql=con.createStatement();
String condition="SELECT * FROM users WHERE username = "+"'"+username+"'";
rs =sql.executeQuery(condition);
while(rs.next())
{ String n=rs.getString("username");
String s=rs.getString("password");
if(username.equals(n)&&password.equals(s))
{
modify=true;
out.print("<h3>密码修改成功!");
String c=
"UPDATE users SET password = "+"'"+password1+"'"+" WHERE username = "+"'"+username+"'";
rs =sql.executeQuery(c);
}
}
}
catch(Exception ex) { ex.printStackTrace();}
}
else
{ out.print("<h3>两次密码输入不一致或新密码长度不够!");
}
if(modify==false&&ifEquals==true)
{ out.print("<br><h3>用户名或旧密码输入错误,请重新输入。");
}
七.
public String getString(String s)
{ String str=s;
try{ byte b[]=str.getBytes("ISO-8859-1");
str=new String(b);
return str;
}
catch(Exception e)
{ return str;
}
}
%>
<% //获取提交的用户名:
String username=request.getParameter("username");
if(username==null)
{username=" ";
}
username=getString(username);
//获取提交的密码:
String password=request.getParameter("password");
if(password==null)
{password=" ";
上一页 [1] [2] [3] [4] [5] [6] [7] 下一页