<!-- #include file=../inc/BBSsetup.asp -->
<!-- #include file=../inc/User_Setup.asp -->
<!-- #include file=../inc/Board_Popfun.asp -->
<!-- #include file=inc/UserTopic.asp -->
<!-- #include file=../inc/Limit_Fun.asp -->
<!-- #include file=inc/Mail_fun.asp -->
<%
Response.Expires = 0 
Response.ExpiresAbsolute = DEF_Now - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private" 
Response.CacheControl = "no-cache"


DEF_BBS_HomeUrl = "../"
initDatabase
GBL_CHK_TempStr = ""

SiteHead(DEF_SiteNameString & " - 用户会员区")
UpdateOnlineUserAtInfo GBL_board_ID,"密码找回"

Dim HomeUrl
HomeUrl = "http://"&Request.ServerVariables("server_name")
If Request.ServerVariables("SERVER_PORT") <> "80" Then HomeUrl = HomeUrl & ":" & Request.ServerVariables("SERVER_PORT")
HomeUrl = Lcase(HomeUrl & Request.Servervariables("SCRIPT_NAME"))
HomeUrl = Replace(HomeUrl,"user/usergetpass.asp","")


Dim SendEmail,SendPass,Question,Answer
Dim SendAnswer,SendUser,SendQuestion,SendPassword1,SendPassword2

UserTopicTopInfo
DisplayUserNavigate("密码找回")%>
<table width=96%>
<tr>
<td>
	<%DisplayGetPassForm%>
</td>
</tr>
</table>
<%
UserTopicBottomInfo
closeDataBase
SiteBottom
If GBL_ShowBottomSure = 1 Then Response.Write GBL_SiteBottomString


Function DisplayGetPassForm

	SendUser = Trim(Request("SendUser"))
	If DEF_User_GetPassMode = 0 Then
		Response.Write "<br><br>&nbsp; &nbsp; 论坛已经关闭密码找回功能。" & VbCrLf
		Exit function
	End If
	If DEF_BBS_EmailMode = 0 and SendUser  <> "" and DEF_User_GetPassMode = 2 Then
		Response.Write "<br><br>&nbsp; &nbsp; 论坛禁止发送邮件，密码找回功能不能使用。" & VbCrLf
		Exit function
	End If
	If Request("submitflag") = "yes" Then
		If Len(SendUser) > 30 Then
			Response.Write "<br><br><font color=ff0000 class=RedFont><b>错误: 用户名太长.</b></font><br>" & VbCrLf
			Exit Function
		End If
			
		Dim Rs,SQL
		SQL = "Select mail,Pass,Question,Answer,UserLimit from LeadBBS_User where UserName='" & Replace(SendUser,"'","''") & "'"
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
		If Rs.Eof Then
			Rs.Close
			Set Rs = Nothing
			Response.Write "<br><br><font color=ff0000 class=RedFont><b>错误: 不存在的用户名.</b></font><br>" & VbCrLf
			Exit Function
		End If

		SendEmail = Rs(0)
		SendPass = Rs(1)
		Question = Rs(2)
		Answer = Rs(3)
		GBL_CHK_UserLimit = Rs(4)
		Rs.Close
		Set Rs = Nothing
		If SendEmail = "" or isNull(SendEmail) Then
			Response.Write "<br><br><font color=ff0000 class=RedFont><b>错误: 此用户注册时未提供Email，无法找回密码.</b></font><br>" & VbCrLf
			Exit Function
		End If

		SQL = GBL_CHK_User
		GBL_CHK_User = SendUser
		CheckisBoardMaster
		If Len(Answer) < 32 or GBL_BoardMasterFlag >= 4 or (GBL_CHK_User <> "" and inStr(GBL_CHK_User,",") = 0 and inStr(LCase(DEF_SupervisorUserName),"," & LCase(GBL_CHK_User) & ",") > 0) Then
			Response.Write "<br><br><font color=ff0000 class=RedFont><b>错误: 此用户未申请密码保护，无法使用找回密码恢复功能。<br>请联系管理员设定密码保护。</b></font><br>" & VbCrLf
			Exit Function
		End If
		GBL_CHK_User = SQL
		
		SendAnswer = Left(Request.Form("SendAnswer"),20)
		SendQuestion = Left(Request.Form("SendQuestion"),20)
		SendPassword2 = Left(Request.Form("SendPassword2"),14)
		SendPassword1 = Left(Request.Form("SendPassword1"),14)

		If SendAnswer = "" and SendQuestion = "" and SendPassword1 = "" and SendPassword2 = "" Then
			DisplaySubmitForm
		Else
			Dim NumCheck
			NumCheck = CheckRndNumber	
			Randomize
			Session(DEF_MasterCookies & "RndNum") = Fix(Rnd*9999)+1		
			If NumCheck = 0 Then
				Response.Write "<br><b><font color=ff0000>验证码填写错误!</font></b><br>" & VbCrLf
				DisplaySubmitForm
				Exit Function
			End If

			If Len(SendPassword2) < 4 or Len(SendPassword1) < 4 or SendPassword1 <> SendPassword2 Then
				Response.Write "<br><b><font color=Red Class=RedFont>新的密码不能少于4位，并且新密码与验证密码必须相同。</font></b> <br>" & VbCrLf
				SendQuestion = ""
				DisplaySubmitForm
				Exit Function
			End If
				
			SQL = "Select LastDoingTime from LeadBBS_OnlineUser where SessionID=" & Session.SessionID
			Set Rs = Con.ExeCute(SQL)
			GBL_DBNum = GBL_DBNum + 1
			If Rs.Eof Then
				GBL_CHK_LastWriteTime = 0
				Rs.Close
				Set Rs = Nothing
				Response.Write "<br><b><font color=Red Class=RedFont>请在线2分钟以上后再进行密码找回!</font></b> <br>" & VbCrLf
				Exit Function
			Else
				GBL_CHK_LastWriteTime = DateDiff("s",RestoreTime(Rs(0)),DEF_Now)
				If GBL_CHK_LastWriteTime < 0 Then GBL_CHK_LastWriteTime = DEF_WriteEventSpace + 1
			End If
			If GBL_CHK_LastWriteTime < DEF_WriteEventSpace * 2 Then
				Response.Write "<br><b><font color=Red Class=RedFont>您的操作太快，勿频烦尝试，请稍候再作提交!</font></b> <br>" & VbCrLf
				DisplaySubmitForm
				Exit Function
			End If
			If MD5(SendAnswer) <> Answer Then
				Response.Write "<br><b><font color=Red Class=RedFont>密码的提示答案填写错误，无法找回账号，或请联系管理员!</font></b> <br>" & VbCrLf
				SendQuestion = ""
				DisplaySubmitForm
				Con.ExeCute("Update LeadBBS_OnlineUser Set LastDoingTime=" & GetTimeValue(DEF_Now) & " where SessionID=" & Session.SessionID)
				GBL_DBNum = GBL_DBNum + 1
				UpdateSessionValue 18,GetTimeValue(DEF_Now),0
				Exit Function
			End If
			
			Dim NewSendPass
			SendPass = MD5(SendPassword2)
			Con.ExeCute("Update LeadBBS_User Set Pass='" & Replace(SendPass,"'","''") & "' where UserName='" & Replace(SendUser,"'","''") & "'")
			If Lcase(GBL_CHK_User) = Lcase(SendUser) Then UpdateSessionValue 7,SendPass,0
			Response.Write "<br><b><font color=Green Class=GreenFont>密码已经成功更改，请使用新的密码<a href=""Login.asp?User=" & urlencode(SendUser) & """>登录</a>您的账号!</font></b><br>" & VbCrLf
			If DEF_User_GetPassMode = 2 Then
				SendGetPassMail SendUser,SendEmail,SendPassword2
				Response.Write "<br><b><font color=Green Class=GreenFont>同时，新的密码已经发送到您的注册邮箱。</font></b><br>" & VbCrLf
			Else
			End If
			Con.ExeCute("Update LeadBBS_OnlineUser Set LastDoingTime=" & GetTimeValue(DEF_Now) & " where SessionID=" & Session.SessionID)
			UpdateSessionValue 18,GetTimeValue(DEF_Now),0
		End If
	Else
		DisplaySubmitForm
	End If

End Function

Function DisplaySubmitForm

	If SendAnswer = "" and SendUser = "" and SendQuestion = "" Then%>
	<script language="javascript">
	function submitonce(theform)
	{
		if (document.all||document.getElementById)
		{
			for (i=0;i<theform.length;i++)
			{
				var tempobj=theform.elements[i];
				if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
				tempobj.disabled=true;
			}
		}
	}
	</script>
<p>
<br>
请输入您的用户名。
<form action=<%=DEF_BBS_HomeUrl%>User/UserGetPass.asp method="post" onSubmit="submitonce(this);">
	用户名: <input name=SendUser type=text maxlength=20 size=22 value="<%
	If GBL_CHK_user = "" or isNull(GBL_CHK_user) Then
		Response.Write htmlencode(Request("user"))
	Else
		Response.Write htmlencode(GBL_CHK_user)
	End If%>" class=fminpt><br>
	<input type=hidden value="yes" name=submitflag><br>
	<input type=submit value="取回密码" class=fmbtn> <input type=reset value="取消" class=fmbtn>
</form>
注意： 版主以上会员及未设立密码保护的用户不支持找回密码
	<%
	Else
		'If SendAnswer = "" and SendQuestion = "" and SendPassword1 = "" and SendPassword2 = "" Then%>
	<script language="javascript">	
	var ValidationPassed = true;
	function submitonce(theform)
	{
		if(theform.sendanswer.value=="")
		{
			alert("请输入你的提示答案!\n");
			ValidationPassed = false;
			theform.sendanswer.focus();
			return;
		}
		if(theform.sendpassword1.value=="")
		{
			alert("请输入你的密码!\n");
			ValidationPassed = false;
			theform.sendpassword1.focus();
			return;
		}

		if(theform.sendpassword2.value=="")
		{
			alert("请输入你的验证密码！\n");
			ValidationPassed = false;
			theform.sendpassword2.focus();
			return;
		}

		if(theform.sendpassword1.value!=theform.sendpassword2.value)
		{
			alert("你的两次密码输入不相同！\n");
			ValidationPassed = false;
			theform.sendpassword1.focus();
			return;
		}
		ValidationPassed = true;
		if (document.all||document.getElementById)
		{
			for (i=0;i<theform.length;i++)
			{
				var tempobj=theform.elements[i];
				if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
				tempobj.disabled=true;
			}
		}
	}
	</script>
<p>
<br>
请输入您的用户名及相关信息。
<form action=<%=DEF_BBS_HomeUrl%>User/UserGetPass.asp method="post" onSubmit="submitonce(this);return ValidationPassed;">
	用 户 名：<input name=SendUser type=text maxlength=20 size=22 value="<%=htmlencode(SendUser)%>" class=fminpt><br>
	<input type=hidden value="yes" name=submitflag>
	密码提示：<input name=sendquestion value="<%=htmlencode(Question)%>" maxlength=14 size=22 readonly class=fminpt><br>
	提示答案：<input name=sendanswer type=text maxlength=20 size=22 value="<%=htmlencode(SendAnswer)%>" class=fminpt><br>
	新的密码：<input name=sendpassword1 type=password maxlength=14 size=22 value="<%=htmlencode(SendPassword1)%>" class=fminpt><br>
	验证密码：<input name=sendpassword2 type=password maxlength=14 size=22 value="<%=htmlencode(SendPassword2)%>" class=fminpt><br>
	<%If DEF_EnableAttestNumber > 0 Then%>
	验 证 码：<input name=ForumNumber maxlength=20 size=20 value="<%=htmlencode(Request("RndNumber"))%>" class=fminpt><br>
	<img src=<%=DEF_BBS_HomeUrl%>images/null.gif height=3 width=2><br>
	请在验证码框输入<img src=<%=DEF_BBS_HomeUrl%>User/number.asp?n=<%=timer%> align=absmiddle width=32 height=12><%End If%>
	<br><br>
	<input type=submit value="取回密码" class=fmbtn> <input type=reset value="取消" class=fmbtn>
</form>
	<%
		'End If
	End If

End Function

Sub SendGetPassMail(Form_UserName,Form_Mail,Form_Password1)

	Dim MailBody,Topic,TextBody
	Topic = "您在" & DEF_SiteNameString & "的密码找回"
	MailBody = "<html>"
	TextBody = ""
	MailBody = MailBody & "<TITLE>账号信息</TITLE>"
	MailBody = MailBody & "<BODY>"
	MailBody = MailBody & "<TABLE BORDER=0 WIDTH=95% ALIGN=CENTER><TBODY><TR>"
	MailBody = MailBody & "<TD VALIGN=MIDDLE ALIGN=TOP><HR WIDTH=100% SIZE=1>"
	TextBody = TextBody & "------------------------------------------" & VbCrLf
	MailBody = MailBody & VbCrLf & htmlencode(Form_UserName)&"，您好：<BR><BR>"
	TextBody = TextBody & htmlencode(Form_UserName)&"，您好：" & VbCrLf & VbCrLf
	MailBody = MailBody & "您在本论坛使用了密码找回，下面是您的账号信息！<BR><BR>"
	TextBody = TextBody & "您在本论坛使用了密码找回，下面是您的账号信息！" & VbCrLf & VbCrLf
	MailBody = MailBody & "用户名："&htmlencode(Form_UserName)&"<BR>"
	TextBody = TextBody & "用户名："&htmlencode(Form_UserName) & VbCrLf
	MailBody = MailBody & "密　码：" & Form_Password1 & "<BR>"
	TextBody = TextBody & "密　码：" & Form_Password1 & VbCrLf
	MailBody = MailBody & "<BR><BR>"
	MailBody = MailBody & "<CENTER><FONT COLOR=RED><a href=""" & HomeUrl & """>欢迎光临论坛！</a></FONT>"
	MailBody = MailBody & "</TD></TR></TBODY></TABLE><BR><HR WIDTH=95% SIZE=1>"
	MailBody = MailBody & "<P ALIGN=CENTER>" & DEF_SiteNameString & " <a href=http://www.leadbbs.com target=_blank class=NavColor>LeadBBS</a> v3.14</P>"
	TextBody = TextBody & VbCrLf & DEF_BBS_HomeUrl & VbCrLf
	TextBody = TextBody & "------------------------------------------" & VbCrLf
	MailBody = MailBody & "</BODY>"
	MailBody = MailBody & "</HTML>"
	Select Case DEF_BBS_EmailMode
		Case 1: If SendEasyMail(Form_Mail,Topic,MailBody,TextBody) = 1 Then
					Response.Write "<br><br>资料成功发送到您的注册邮箱！"
				Else
					Response.Write "<br><br>论坛未正确设置邮件发送，资料发送失败！"
				End If
		Case 2: If SendJmail(Form_Mail,Topic,MailBody) = 1 Then
					Response.Write "<br><br>资料成功发送到您的注册邮箱！"
				Else
					Response.Write "<br><br>论坛未正确设置邮件发送，资料发送失败2！"
				End If
		Case 3: If SendCDOMail(Form_Mail,Topic,TextBody) = 1 Then
					Response.Write "<br><br>资料成功发送到您的注册邮箱！"
				Else
					Response.Write "<br><br>论坛未正确设置邮件发送，资料发送失败！"
				End If
		Case Else: 
	End Select

End Sub

Function CheckRndNumber

	If DEF_EnableAttestNumber = 0 Then
		CheckRndNumber = 1
		Exit Function
	End If

	Dim RndNumber
	Dim Rs
	RndNumber = Left(Session(DEF_MasterCookies & "RndNum") & "",4)
	If RndNumber = "" or isNumeric(RndNumber) = 0 Then
		'RndNumber = 0
		Randomize
		RndNumber = Fix(Rnd*9999)+1
		Session(DEF_MasterCookies & "RndNum") = RndNumber
	End If
	RndNumber = cCur(RndNumber)
	If RndNumber = 0 Then
		RndNumber = 9999999
	End If
	
	Dim ForumNumber
	ForumNumber = Left(Request.Form("ForumNumber"),4)
	If isNumeric(ForumNumber) = False Then ForumNumber = 0
	ForumNumber = Fix(cCur(ForumNumber))
	If RndNumber = ForumNumber and RndNumber > 0 Then
		CheckRndNumber = 1
	Else
		CheckRndNumber = 0
	End If

End Function%>