<!--#include file="../conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../inc/function.asp"-->
<!--#include file="../inc/Language.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户找回密码</title>
</head>
<body>
<%
Dim act

act=Trim(Request.QueryString("act"))
Dim AskD
Set AskD = Server.CreateObject("KwAsk.FunAsk")
	opendb
	set AskD.myConn =conn
	AskD.myPredb =predb
	AskD.Getsetting()
	siteinfo=AskD.siteinfo
	setting=AskD.setting
Select Case act
   Case "2"
   Call form2()
   Case "3"
   Call form3()
   Case "4"
   Call form4()
   Case Else
   Call form1()
End Select
set AskD.myConn =Nothing
Closedb
Set AskD = Nothing

Sub form1()
%>
<table border="0" cellpadding="0" cellspacing="0">
  <form action="?act=2" method="post">
  <tr>
    <td width="147">请输入你的用户名：</td>
    <td width="160"><input type="text" name="userid" /></td>
    <td><input type="submit" name="button" id="button" value="下一步" /></td>
  </tr>
  </form>
</table>
<%
End Sub

Sub Form2()
Dim rs,userid
userid=Trim(Request.Form("userid"))
IF Userid="" Then userid=0
set rs=conn.execute("select id,regQuestion from "&predb&"user where userid='"&userid&"'")
IF rs.bof and rs.eof Then
   Response.Write("您查找的用户名不存在！")
Else
   IF rs("regQuestion")&""<>"" Then
%>
<table border="0" cellpadding="0" cellspacing="0">
  <form action="?act=3" method="post"><input name="id" type="hidden" value="<%= rs("id") %>" />
  <tr>
    <td width="147">您的提示问题：</td>
    <td width="160"><input name="regquestion" type="text" id="regquestion" value="<%= rs("regQuestion") %>" readonly="readonly"/></td>
    </tr>
  <tr>
    <td>您的回答内容：</td>
    <td><input name="regans" type="text" id="regans" /></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="button" id="button" value="下一步" /></td>
    </tr>
  </form>
</table>
<%
   Else
    Call GetPass(rs("id"))
   End IF
End IF
Set rs=nothing
End Sub

Sub Form3()
Dim rs,id,regans
id=Trim(Request.Form("id"))
regans=Trim(Request.Form("regans"))
set rs=conn.execute("select id from "&predb&"user where id="&id&" and regans='"&md5(regans,16)&"'")
IF rs.bof and rs.eof Then
   Response.Write("您的密码提示答案不正确！")
Else
%>
<table border="0" cellpadding="0" cellspacing="0">
  <form action="?act=4" method="post"><input name="id" type="hidden" value="<%= rs("id") %>" />
  <tr>
    <td width="147">新的密码：</td>
    <td width="160"><input name="psd1" type="password"/></td>
    </tr>
  <tr>
    <td>确认密码：</td>
    <td><input name="psd2" type="password"/></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="button" id="button" value="下一步" /></td>
    </tr>
  </form>
</table>
<%
End IF
Set rs=nothing
End Sub

Sub Form4()
Dim rs,id,psd1,psd2
id=Trim(Request.Form("id"))
psd1=Trim(Request.Form("psd1"))
psd2=Trim(Request.Form("psd2"))
IF psd1<>psd2 or Psd1="" Then Response.Write("密码不正确"):Response.End()
set rs=conn.execute("update "&predb&"user set userpass='"&md5(psd1,16)&"' where id="&id)
Set rs=nothing
Response.Write("密码修改成功！")
End Sub

Sub GetPass(uid)
Dim rs,sql,userpass
   IF AskD.chkMailObject then
   userpass=AskD.NewPass()
	 set rs = Server.CreateObject("adodb.recordset")
	 sql="select userpass,Usermail from "&predb&"user where id="&uid
	 rs.open sql,conn,1,3
	    ToMail=rs("Usermail")
	    Rs("userpass")=md5(userpass,16)
	 rs.update
	 rs.close
	 set rs=nothing
	 Dim From,FromName,Topic,MailBody,ToMail,SmtpName,SmtpPass,MailSmtp
			Topic=siteInfo(4)&" - 找回密码"
			MailBody=" 您于 "&now()&" 修改了您的密码，您的新密码是：<b>"&userpass&"</b> &nbsp;&nbsp;--"&siteInfo(4)
			MailSmtp=setting(39)
			SmtpName=setting(40)
			SmtpPass=setting(41)
			From=setting(42)
			FromName=siteInfo(4)
	 '发送激活邮件
		Call AskD.SendMail(From,FromName,Topic,MailBody,ToMail,SmtpName,SmtpPass,MailSmtp)
		IF AskD.Isgo then 
			 Response.Write "邮件已经发送到你的邮箱，请查收！"
		Else
			 Response.Write "邮件发送失败，请联系管理员修改密码！"
		End IF
   Else
     Response.Write("服务器不支持邮件发送，请联系管理员！")
   End IF
End Sub
%>
</body>
</html>
