<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/email.asp"-->
<!--#include file="inc/md5.asp"-->
<%
Dim Founderr
Dim useremail
Dim topic
Dim mailbody
Dim sendmsg
Dim answer
Dim repassword
Dim username
Dim password
Dim DownloadClass_Ads
Dim rs
Dim sql
Dim Errmsg
Dim Sucmsg
Dim NowStats
Dim HtmlTitle
Dim Style_CSS
Dim HtmlTempStr
Dim TempTopStr
Dim TempFootStr
SendPass
If IsObject(DownloadClass_Ads) Then
	Set DownloadClass_Ads = Nothing
End If
CloseConn
Public Sub SendPass()
	Founderr = False
	DownsysClass.LoadTemplates ("")
	Set DownloadClass_Ads = New Adcolumn_Cls
	Set Rs = Server.CreateObject("adodb.recordset")
	NowStats = "找回密码"
	HtmlTitle = "找回密码"
	TempTopStr = DownsysClass.mainhtml(0) & DownsysClass.mainhtml(1) & DownsysClass.mainhtml(2) & DownsysClass.mainhtml(3)
	TempFootStr = DownsysClass.mainhtml(4)
	Style_CSS = Replace(Replace(DownsysClass.Style_CSS, "{$SetupDir}", DownsysClass.SetupDir), "{$PicUrl}", DownsysClass.TempDir)
	HtmlTempStr = TempTopStr
	HtmlTempStr = Replace(HtmlTempStr, "{$NavMenu}", DownsysClass.SortingMenu)
	HtmlTempStr = Replace(HtmlTempStr, "{$Width}", DownsysClass.mainset(0))
	HtmlTempStr = Replace(HtmlTempStr, "{$Style_CSS}", Style_CSS)
	If CInt(DownsysClass.Setting(5)) = 0 Then
		HtmlTempStr = Replace(HtmlTempStr, "{$TopMeun}", DownsysClass.mainset(9))
	Else
		HtmlTempStr = Replace(HtmlTempStr, "{$TopMeun}", DownsysClass.mainset(10))
	End If
	HtmlTempStr = Replace(HtmlTempStr, "{$NowStats}", NowStats)
	HtmlTempStr = Replace(HtmlTempStr, "{$Title}", HtmlTitle)
	HtmlTempStr = Replace(HtmlTempStr, "{$Adcolumn(0)}", DownloadClass_Ads.RunScriptAds(7))
	HtmlTempStr = Replace(HtmlTempStr, "{$Adcolumn(1)}", DownloadClass_Ads.BannerAds(7))
	HtmlTempStr = Replace(HtmlTempStr, "{$Adcolumn(2)}", DownloadClass_Ads.AdsColumn(7, 2))
	HtmlTempStr = Replace(HtmlTempStr, "{$Adcolumn(3)}", DownloadClass_Ads.AdsColumn(7, 3))
	Response.Write HtmlTempStr
	If CInt(DownsysClass.Setting(5)) = 1 Then
		TempFootStr = Replace(TempFootStr, "{$FootMeun}", DownsysClass.mainset(11))
	Else 
		TempFootStr = Replace(TempFootStr, "{$FootMeun}", DownsysClass.mainset(44))
	End If
	TempFootStr = Replace(TempFootStr, "{$Width}", DownsysClass.mainset(0))
	TempFootStr = Replace(TempFootStr, "{$Adcolumn(4)}", DownloadClass_Ads.ScriptFloatAds(7))
	TempFootStr = Replace(TempFootStr, "{$Adcolumn(5)}", DownloadClass_Ads.ScriptFixedAds(7))
	Response.Write "<TABLE width="""
	Response.Write DownsysClass.mainset(0)
	Response.Write """ class=tableBorder cellSpacing=0 cellPadding=0 align=center border=0>"
	Response.Write " <TR>"
	Response.Write " <TH width=""75%"">找回密码"
	Response.Write "</TH></TR>"
	Response.Write " <TR>"
	Response.Write " <TD height=300 class=Border2 align=center>"
	Founderr = False
	If Founderr Then
		Response.Write "<script>alert('" & Errmsg & "');history.go(-1)</script>"
	Else
		If Request("action") = "step1" Then
			Call step1
		ElseIf Request("action") = "step2" Then
			Call step2
		ElseIf Request("action") = "step3" Then
			Call step3
		Else
			Call main
		End If
		If Founderr Then Response.Write "<script>alert('" & Errmsg & "');history.go(-1)</script>"
	End If
	Response.Write "</TD></TR></TABLE>"
	Response.Write TempFootStr
End Sub

Private Sub step1()
	If Request("username") = "" Then
		Founderr = True
		Errmsg = Errmsg + "请输入您的用户名。"
		Exit Sub
	Else
		UserName = Replace(Request("username"), "'", "")
	End If
	If CInt(DownsysClass.Setting(13)) = 1 Then
		Set Rs = DownsysClass.Execute("Select * from [NC_User] where username='" & UserName & "'")
	Else
		Set Rs = DownsysClass.Execute("Select * from [NC_User] where username='" & UserName & "'")
	End If
	If Rs.EOF And Rs.bof Then
		Founderr = True
		Errmsg = Errmsg + "您输入的用户名并不存在，请重新输入。或者由于该系统不支持邮件发送，只能通过联系站长获得密码。"
	Else
		If Rs(13) = "" Or IsNull(Rs(13)) Then
			Founderr = True
			Errmsg = Errmsg + "该用户没有填写密码问题及答案，只有填写的用户方能继续。"
		Else
			Response.Write "<form action=""sendpass.asp?action=step2"" method=""post""> "
			Response.Write "<table cellpadding=4 cellspacing=1 align=center class=tableBody>"
			Response.Write " <tr>"
			Response.Write " <th valign=middle colspan=2 align=center height=25>取回密码（第二步：回答问题）</th></tr>"
			Response.Write " <tr>"
			Response.Write " <td valign=middle class=Border2><b>问题：</b></td>"
			Response.Write " <td class=Border2 valign=middle>"
			Response.Write Rs("question")
			Response.Write "</td>"
			Response.Write " </tr>"
			Response.Write " <tr>"
			Response.Write " <td class=Border2 valign=middle><b>答案：</b></td>"
			Response.Write " <td class=Border2 valign=middle><INPUT name=""answer"" type=text class=inputbody></td>"
			Response.Write " </tr>"
			Response.Write " <tr>"
			Response.Write " <td class=Border2 colspan=2>"
			Response.Write " <b>说明：</b>请填写您正确的问题答案。</td></tr>"
			Response.Write " <tr>"
			Response.Write " <td class=Border1 valign=middle colspan=2 align=center><input type=submit name=""submit"" value="" 下一步 "" class=button></td></tr>"
			Response.Write "</table>"
			Response.Write "<input type=hidden value="""
			Response.Write UserName
			Response.Write """ name=username>"
			Response.Write "</form>"
		End If
	End If
	Rs.Close
	Set Rs = Nothing
End Sub

Private Sub step2()
	If Request("username") = "" Then
		Founderr = True
		Errmsg = Errmsg + "请输入您的用户名。"
		Exit Sub
	Else
		UserName = Replace(Request("username"), "'", "")
	End If
	If DownsysClass.checkpost = False Then
		Errmsg = Errmsg + "您提交的数据不合法，请不要从外部提交发言。"
		Founderr = True
		Exit Sub
	End If
	If Request("answer") = "" Then
		Founderr = True
		Errmsg = Errmsg + "请输入您的问题答案。"
		Exit Sub
	Else
		Answer = md5(Trim(Request("answer")))
	End If
	Set Rs = DownsysClass.Execute("select * from NC_User where username = '" & UserName & "' and answer = '" & Answer & "'")
	If Rs.EOF And Rs.bof Then
		Founderr = True
		Errmsg = Errmsg + "您输入的问题答案不正确，请重新输入。"
		Exit Sub
	Else
		Response.Write "<form action=""sendpass.asp?action=step3"" method=""post""> "
		Response.Write "<table cellpadding=3 cellspacing=1 class=tablebody align=center>"
		Response.Write " <tr>"
		Response.Write " <th valign=middle colspan=2 height=25>取回密码（第三步：修改密码）</th></tr>"
		Response.Write " <tr>"
		Response.Write " <td class=Border2 valign=middle><b>问题：</b></td>"
		Response.Write " <td class=Border2 valign=middle>"
		Response.Write Rs("question")
		Response.Write "</td>"
		Response.Write " </tr>"
		Response.Write " <tr>"
		Response.Write " <td class=Border2 valign=middle><b>答案：</b></td>"
		Response.Write " <td class=Border2 valign=middle>"
		Response.Write Request("answer")
		Response.Write "</td>"
		Response.Write " </tr>"
		Response.Write " <tr>"
		Response.Write " <td class=Border2 valign=middle><b>新密码：</b></td>"
		Response.Write " <td class=Border2 valign=middle><input type=password name=password class=inputbody></td>"
		Response.Write " </tr>"
		Response.Write " <tr>"
		Response.Write " <td class=Border2 valign=middle><b>确认新密码：</b></td>"
		Response.Write " <td class=Border2 valign=middle><input type=password name=repassword class=inputbody></td>"
		Response.Write " </tr>"
		Response.Write " <tr>"
		Response.Write " <td class=Border2 colspan=2>"
		Response.Write " <b>说明：</b>"
		Response.Write " "
		If CInt(DownsysClass.Setting(13)) > 0 Then
			Response.Write " 系统将会自动发一封邮件到您注册时填写的邮箱，在打开邮件中的密码激活地址后，您的新密码将正式启用。"
			Response.Write " "
		Else
			Response.Write " 请填写您的新密码，并记住您所填写信息。"
		End If
		Response.Write " </td></tr>"
		Response.Write " <tr>"
		Response.Write " <td class=Border1 valign=middle colspan=2 align=center><input type=submit name=""submit"" value=""下一步"" class=button></td></tr>"
		Response.Write "</table>"
		Response.Write "<input type=hidden value="""
		Response.Write Request("answer")
		Response.Write """ name=answer>"
		Response.Write "<input type=hidden value="""
		Response.Write UserName
		Response.Write """ name=username>"
		Response.Write "</form>"
	End If
	Rs.Close
	Set Rs = Nothing
End Sub

Private Sub step3()
	If Request("username") = "" Then
		Founderr = True
		Errmsg = Errmsg + "请输入您的用户名。"
		Exit Sub
	Else
		UserName = Replace(Request("username"), "'", "")
	End If
	If Request("answer") = "" Then
		Founderr = True
		Errmsg = Errmsg + "请输入您的问题答案。"
		Exit Sub
	Else
		Answer = md5(Request("answer"))
	End If
	If Request("password") = "" Or Len(Request("password")) > 15 Or Len(Request("password")) < 6 Then
		Founderr = True
		Errmsg = Errmsg + "请输入您的新密码(长度不能大于15小于6)。"
		Exit Sub
	ElseIf Request("repassword") = "" Then
		Founderr = True
		Errmsg = Errmsg + "请再次输入您的新密码。"
		Exit Sub
	ElseIf Request("password") <> Request("repassword") Then
		Founderr = True
		Errmsg = Errmsg + "您输入的新密码和确认不一样，请确认您填写的信息。"
		Exit Sub
	Else
		PassWord = md5(Request("password"))
	End If
	Set Rs = CreateObject("adodb.recordset")
	SQL = "select * from [NC_user] where username='" & UserName & "' and answer='" & Answer & "'"
	Rs.Open SQL, conn, 1, 3
	If Rs.EOF And Rs.bof Then
		Founderr = True
		Errmsg = Errmsg + "您输入的问题答案不正确，请重新输入。"
	Else
		If CInt(DownsysClass.Setting(13)) = 1 Then
			RePassword = Request.Form("password")
			Answer = Request.Form("answer")
			PassWord = Rs("password")
			UsereMail = Rs("usermail")
			Call sendusermail
			If SendMail = "OK" Then
				SendMsg = "系统已经发送一封邮件到您注册时填写的邮箱，在打开邮件中的密码激活地址后，您的新密码将正式启用。"
			Else
				Rs("password") = md5(RePassword)
				Rs.Update
				SendMsg = "由于系统错误，给您发送的密码资料未成功。您已经修改密码成功，请使用新密码登陆系统。"
			End If
		Else
			Rs("userpass") = PassWord
			Rs.Update
		End If
		Response.Write "<form action=""login.asp"" method=""post""> "
		Response.Write "<table cellpadding=3 cellspacing=1 class=tablebody align=center>"
		Response.Write " <tr>"
		Response.Write " <th valign=middle colspan=2>取回密码（第四步：修改成功）</th></tr>"
		Response.Write " <tr>"
		Response.Write " <td class=Border2 valign=middle><b>问题：</b></td>"
		Response.Write " <td class=Border2 valign=middle>"
		Response.Write Rs(13)
		Response.Write "</td>"
		Response.Write " </tr>"
		Response.Write " <tr>"
		Response.Write " <td class=Border2 valign=middle><b>答案：</b></td>"
		Response.Write " <td class=Border2 valign=middle>"
		Response.Write Request("answer")
		Response.Write "</td>"
		Response.Write " </tr>"
		Response.Write " <tr>"
		Response.Write " <td class=Border2 valign=middle><b>新密码：</b></td>"
		Response.Write " <td class=Border2 valign=middle>"
		Response.Write Request("password")
		Response.Write "</td>"
		Response.Write " </tr>"
		Response.Write " <tr>"
		Response.Write " <td class=Border2 colspan=2>"
		Response.Write " <b>说明：</b>"
		Response.Write " "
		If CInt(DownsysClass.Setting(13)) = 1 Then
			Response.Write SendMsg
			Response.Write " "
		Else
			Response.Write " 请记住您的新密码并使用新密码<a href=login.asp>登陆</a>。"
			Response.Write " "
		End If
		Response.Write "</td></tr>"
		Response.Write " <tr>"
		Response.Write " <td class=Border1 valign=middle colspan=2 align=center><input type=submit name=""submit"" value=""返 回"" class=button></td></tr>"
		Response.Write "</table>"
		Response.Write "</form>"
	End If
	Rs.Close
	Set Rs = Nothing
End Sub

Private Sub main()
	Response.Write "<form action=""sendpass.asp?action=step1"" method=""post""> "
	Response.Write "<table cellpadding=6 cellspacing=1 align=center class=tablebody>"
	Response.Write " <tr>"
	Response.Write " <th valign=middle colspan=2>取回密码</b>（第一步：用户名）</th></tr>"
	Response.Write " <tr>"
	Response.Write " <td class=Border2 valign=middle>请输入您的用户名</td>"
	Response.Write " <td class=Border2 valign=middle><INPUT name=""username"" type=text class=inputbody></td>"
	Response.Write " </tr>"
	Response.Write " <tr>"
	Response.Write " <td class=Border2 colspan=2>"
	Response.Write " <b>说明：</b>本操作只能修改您的密码，不能对原密码进行修改，请确认您已经填写了密码问题及答案。</td></tr>"
	Response.Write " <tr>"
	Response.Write " <td class=Border1 valign=middle colspan=2 align=center><input type=submit name=""submit"" value="" 下一步 "" class=button></td></tr>"
	Response.Write "</table>"
	Response.Write "</form>"
End Sub

Private Sub sendusermail()
	On Error Resume Next
	Topic = "您在" & DownsysClass.Setting(0) & "的密码信息"
	MailBody = MailBody & "<style>A:visited { TEXT-DECORATION: none }"
	MailBody = MailBody & "A:active  { TEXT-DECORATION: none }"
	MailBody = MailBody & "A:hover   { TEXT-DECORATION: underline overline }"
	MailBody = MailBody & "A:link    { text-decoration: none;}"
	MailBody = MailBody & "A:visited { text-decoration: none;}"
	MailBody = MailBody & "A:active  { TEXT-DECORATION: none;}"
	MailBody = MailBody & "A:hover   { TEXT-DECORATION: underline overline}"
	MailBody = MailBody & "BODY   { FONT-FAMILY: 宋体; FONT-SIZE: 9pt;}"
	MailBody = MailBody & "TD    { FONT-FAMILY: 宋体; FONT-SIZE: 9pt }</style>"
	MailBody = MailBody & "<TABLE border=0 width='95%' align=center><TBODY><TR>"
	MailBody = MailBody & "<TD valign=middle align=top>"
	MailBody = MailBody & "" & DownsysClass.htmlencode(UserName) & "，您好：<br><br>"
	MailBody = MailBody & "欢迎您使用本系统的密码遗忘功能，<b>假如您不希望更改您的密码，请不要点击下面的激活连接</b>。<br>"
	MailBody = MailBody & "<a href=http://" & Request.servervariables("server_name") & Replace(Request.servervariables("script_name"), "sendpass.asp", "") & "activepass.asp?username=" & DownsysClass.htmlencode(UserName) & "&pass=" & PassWord & "&repass=" & RePassword & "&answer=" & Answer & ">http://" & Request.servervariables("server_name") & Replace(Request.servervariables("script_name"), "sendpass.asp", "") & "activepass.asp?username=" & DownsysClass.htmlencode(UserName) & "&pass=" & PassWord & "&repass=" & RePassword & "&answer=" & Answer & "</a>"
	MailBody = MailBody & "<br><br>"
	MailBody = MailBody & "<center><font color=red>再次欢迎你支持本站，让我们一起来建设这个网上家园！</font>"
	MailBody = MailBody & "</TD></TR></TBODY></TABLE><br><hr width=95% size=1>"
	MailBody = MailBody & "<center>" & DownsysClass.Setting(0)
	Select Case CInt(DownsysClass.Setting(10))
		Case 0
			SendMsg = "由于系统错误，给您发送的密码资料未成功。请点击右边的连接将您的密码激活：<a href=http://" & Request.servervariables("server_name") & Replace(Request.servervariables("script_name"), "sendpass.asp", "") & "activepass.asp?username=" & DownsysClass.htmlencode(UserName) & "&pass=" & PassWord & "&repass=" & RePassword & "><B>激活密码</B></a>"
		Case 1
			Call jmail(UsereMail, Topic, MailBody)
		Case 2
			Call Cdonts(UsereMail, Topic, MailBody)
		Case 3
			Call aspemail(UsereMail, Topic, MailBody)
		Case Else
			SendMsg = "由于系统错误，给您发送的密码资料未成功。请点击右边的连接将您的密码激活：<a href=http://" & Request.servervariables("server_name") & Replace(Request.servervariables("script_name"), "sendpass.asp", "") & "activepass.asp?username=" & DownsysClass.htmlencode(UserName) & "&pass=" & PassWord & "&repass=" & RePassword & "><B>激活密码</B></a>"
	End Select
End Sub
%>
