<!--#include file=conn.asp-->
<!--#include file=config.asp-->
<!--#include file=const.asp-->
<!--#include file=char.asp-->
<!--#include file=inc/email.asp-->
<!--#include file=md5.asp-->
<%
 '=========================================================
' File: lostpass.asp
' Version:3.0
' Date: 2005-9-27
' Script Written by xmrxw
'=========================================================
' Copyright (C) 2004,2005 Xmrxw.Com All rights reserved.
' Web: http://www.xmrxw.com,http://www.xmzxw.com
' Email: info@mssky.com,super@mssky.com
' QQ：10689579　Msn：zdlmicr@hotmail.com
'=========================================================
dim topic,mailbody,sendmsg,useremail
dim username,password,repassword
dim answer
stats="取回密码"
call nav()
call head_var("忘记密码","lostpass.asp")
if founderr then
	call MsLove_error()
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 call MsLove_error()
end if
call footer()
call activeonline()

sub step1()
if Not ChkPost then'查检提交数据
	ErrMsg=ErrMsg+"<Br>"+"<li>您提交的数据不合法，请不要从外部提交发言。"
   	FoundErr=True
	exit sub
end if
dim Reguserlens
Reguserlens=split(Reguserlen,"|")
if trim(request("Username"))="" or strLength(trim(request("Username")))>Cint(Reguserlens(1)) or strLength(trim(request("Username")))<Cint(Reguserlens(0)) then
	errmsg=errmsg+"<br>"+"<li>请输入您的用户名(长度不能大于"&Reguserlens(0)&"小于"&Reguserlens(1)&")。"
	founderr=true
else
	username=trim(request("Username"))
end if
if Instr(trim(request("Username")),"=")>0 or Instr(trim(request("Username")),"%")>0 or Instr(trim(request("Username")),chr(32))>0 or Instr(trim(request("Username")),"?")>0 or Instr(trim(request("Username")),"&")>0 or Instr(trim(request("Username")),";")>0 or Instr(trim(request("Username")),",")>0 or Instr(trim(request("Username")),"'")>0 or Instr(trim(request("Username")),",")>0 or Instr(trim(request("Username")),chr(34))>0 or Instr(trim(request("Username")),chr(9))>0 or Instr(trim(request("Username")),"")>0 or Instr(trim(request("Username")),"$")>0 then
	errmsg=errmsg+"<br>"+"<li>用户名中含有非法字符。"
	founderr=true
else
	username=replace(trim(request("username")),"'","")
end if
if Mailtype>0 then
	set rs=conn.execute("Select UserQuesion,UserAnswer,Username,Usergroupid from [Ms_user] where username='"&username&"'")
else
	set rs=conn.execute("Select UserQuesion,UserAnswer,Username,Usergroupid from [Ms_user] where username='"&username&"' and UserGroupID>3")
end if
if rs.eof and rs.bof then
	Founderr=true
	errmsg=Errmsg+"<br>"+"<li>您输入的用户名并不存在，请重新输入。<li>或者由于该系统不支持邮件发送，而您的等级为注册用户级别，只能通过联系管理员获得密码。"
elseif rs(3) < 4 then
	Founderr=true
	errmsg=Errmsg+"<br>"+"<li>您是管理员或者是管家，只能通过联系管理员获得密码。"
else
	if rs(0)="" or isnull(rs(0)) then
		Founderr=true
		Errmsg=Errmsg+"<br>"+"<li>该用户没有填写密码问题及答案，只有填写的用户方能继续。"
	else
%>
<table cellpadding=1 cellspacing=1 align=center class=tableborder1>
<form action="lostpass.asp?action=step2" method="post"> 
    <tr>
    <th valign=middle colspan=2 align=center height=25>取回密码（第二步：回答问题）</th></tr>
    <tr>
    <td valign=middle class=tablebody1><b>问题：</b></td>
    <td class=tablebody1 valign=middle><%=rs(0)%></td>
    </tr>
    <tr>
    <td class=tablebody1 valign=middle><b>答案：</b></td>
    <td class=tablebody1 valign=middle><input class=2 name="answer" type=text></td>
    </tr>
    <tr>
    <td class=tablebody1 colspan=2>
    <b>说明：</b>请填写您正确的问题答案。</td></tr>
    <tr>
    <td class=tablebody2 valign=middle colspan=2 align=center><input class=2 type=submit name="submit" value="提 交"></td></tr>
	<input type=hidden value="<%=username%>" name=username>
</form>
</table>
<%
		end if
	end if
	rs.close
	set rs=nothing
end sub

sub step2()
	dim answer
	if request("username")="" then
		Founderr=true
		Errmsg=Errmsg+"<br>"+"<li>请输入您的用户名。"
		exit sub
	else
		username=replace(request("username"),"'","")
	end if
if Not ChkPost then'查检提交数据
	ErrMsg=ErrMsg+"<Br>"+"<li>您提交的数据不合法，请不要从外部提交发言。"
   	FoundErr=True
	exit sub
end if
	if request("answer")="" then
		Founderr=true
		Errmsg=Errmsg+"<br>"+"<li>请输入您的问题答案。"
		exit sub
	else
		answer=md5(request("answer"),16)
	end if
	set rs=conn.execute("select UserQuesion,UserAnswer from [Ms_user] where username='"&username&"' and Useranswer='"&answer&"'")
	if rs.eof and rs.bof then
		Founderr=true
		Errmsg=Errmsg+"<br>"+"<li>您输入的问题答案不正确，请重新输入。"
	else
%>
<table cellpadding=3 cellspacing=1 class=tableborder1 align=center>
<form action="lostpass.asp?action=step3" method="post"> 
    <tr>
    <th valign=middle colspan=2 height=25>取回密码（第三步：修改密码）</th></tr>
    <tr>
    <td class=tablebody1 valign=middle><b>问题：</b></td>
    <td class=tablebody1 valign=middle><%=rs(1)%></td>
    </tr>
	 <%if Cint(Codeshow(8))=1 then%>
    <tr> 
      <td height="27"  valign=middle class=tablebody1>检验码：</td>
      <td  valign=middle class=tablebody1> <input type="text" name="codestr" maxlength="4" size="4"> 
        &nbsp;<%=GetCode()%>&nbsp;</td>
    </tr>
    <%end if%>
    <tr>
    <td class=tablebody1 valign=middle><b>答案：</b></td>
    <td class=tablebody1 valign=middle><%=request("answer")%></td>
    </tr>
    <tr>
    <td class=tablebody1 valign=middle><b>新密码：</b></td>
    <td class=tablebody1 valign=middle><input class=2 type=password name=password></td>
    </tr>
    <tr>
    <td class=tablebody1 valign=middle><b>确认新密码：</b></td>
    <td class=tablebody1 valign=middle><input class=2 type=password name=repassword></td>
    </tr>
    <tr>
    <td class=tablebody1 colspan=2>
    <b>说明：</b>
	<%if Mailtype>0 then%>
	系统将会自动发一封邮件到您注册时填写的邮箱，在打开邮件中的密码激活地址后，您的新密码将正式启用。
	<%else%>
	请填写您的交友新密码，并记住您所填写信息。<%end if%>
	</td></tr>
    <tr>
    <td class=tablebody2 valign=middle colspan=2 align=center><input class=2 type=submit name="submit" value="提 交"></td></tr>
	<input type=hidden value="<%=request("answer")%>" name=answer>
<input type=hidden value="<%=username%>" name=username>
</form>
</table>
<%
	end if
	rs.close
	set rs=nothing
end sub

sub step3()
if Not ChkPost then'查检提交数据
	ErrMsg=ErrMsg+"<Br>"+"<li>您提交的数据不合法，请不要从外部提交发言。"
   	FoundErr=True
end if

if Cint(Codeshow(8))=1 then
	if Not CodeIsTrue() then
		errmsg=errmsg+"<br>"+"<li>验证码校验失败，请返回刷新页面后再输入验证码。"
		founderr=true
	end if
end if

	if request("username")="" then
		Founderr=true
		Errmsg=Errmsg+"<br>"+"<li>请输入您的用户名。"
		exit sub
	else
		username=replace(request("username"),"'","")
	end if
	if request("answer")="" then
		Founderr=true
		Errmsg=Errmsg+"<br>"+"<li>请输入您的问题答案。"
		exit sub
	else
		answer=md5(request("answer"),16)
	end if
	if request("password")="" or Len(request("password"))>10 or len(request("password"))<6 then
		Founderr=true
		Errmsg=Errmsg+"<br>"+"<li>请输入您的新密码(长度不能大于10小于6)。"
		exit sub
	elseif request("repassword")="" then
		Founderr=true
		Errmsg=Errmsg+"<br>"+"<li>请再次输入您的新密码。"
		exit sub
	elseif request("password")<>request("repassword") then
		Founderr=true
		Errmsg=Errmsg+"<br>"+"<li>您输入的新密码和确认不一样，请确认您填写的信息。"
		exit sub
	else
		password=md5(request("password"),16)
	end if
	set rs=server.createobject("adodb.recordset")
	sql="select userpassword,useremail,Userquesion,userclass,UserGroupID from [Ms_user] where username='"&username&"' and useranswer='"&answer&"'"
	rs.open sql,conn,1,3
	if rs.eof and rs.bof then
		Founderr=true
		Errmsg=Errmsg+"<br>"+"<li>您输入的问题答案不正确，请重新输入。"
	else
		if Mailtype>0 then
			repassword=request.form("password")
			answer=request.form("answer")
			password=rs("userpassword")
			useremail=rs("useremail")
			call sendusermail()
			if SendMail="OK" then
			sendmsg="系统已经发送一封邮件到您注册时填写的邮箱，在打开邮件中的密码激活地址后，您的新密码将正式启用。"
			elseif rs("UserGroupID")<4 then
			sendmsg="由于系统错误，给你发送的密码资料未成功，您的等级为版主以上级别，为了安全起见，请联系管理员获得密码。"
			else
			rs("userpassword")=md5(repassword,16)
			rs.update
			sendmsg="由于系统错误，给您发送的密码资料未成功。您已经修改密码成功，请使用新密码登陆系统。"
			end if
		else
			rs("userpassword")=password
			rs.update
		end if
%>
<table cellpadding=3 cellspacing=1 class=tableborder1 align=center>
<form action="login.asp" method="post"> 
    <tr>
    <th valign=middle colspan=2>取回密码（第四步：修改成功）</th></tr>
    <tr>
    <td class=tablebody1 valign=middle><b>问题：</b></td>
    <td class=tablebody1 valign=middle><%=rs(2)%></td>
    </tr>
    <tr>
    <td class=tablebody1 valign=middle><b>答案：</b></td>
    <td class=tablebody1 valign=middle><%=request("answer")%></td>
    </tr>
    <tr>
    <td class=tablebody1 valign=middle><b>新密码：</b></td>
    <td class=tablebody1 valign=middle><%=request("password")%></td>
    </tr>
    <tr>
    <td class=tablebody1 colspan=2>
    <b>说明：</b>
	<%if Mailtype>0 then%>
<%=sendmsg%>
	<%else%>
	请记住您的新密码并使用新密码<a href=login.asp>登陆交友</a>。
	<%end if%></td></tr>
    <tr>
    <td class=tablebody2 valign=middle colspan=2 align=center><input class=2 type=submit name="submit" value="返 回"></td></tr>
	</form>
</table>
<%
	end if
	rs.close
	set rs=nothing
end sub

sub main()
%>
<table cellpadding=6 cellspacing=1 align=center class=tableborder1>
<form action="lostpass.asp?action=step1" method="post"> 
    <tr>
    <th valign=middle colspan=2>取回密码</b>（第一步：用户名）</th></tr>
    <tr>
    <td class=tablebody1 valign=middle>请输入您的用户名</td>
    <td class=tablebody1 valign=middle><input class=2 name="username" type=text></td>
    </tr>
    <tr>
    <td class=tablebody1 colspan=2>
    <b>说明：</b>本操作只能修改您的密码，不能对原密码进行修改，请确认您已经填写了密码问题及答案。</td></tr>
    <tr>
    <td class=tablebody2 valign=middle colspan=2 align=center><input class=2 type=submit name="submit" value="提 交"></td></tr>
	</form>
</table>
<%
end sub

sub sendusermail()
	on error resume next
	topic="您在" & webname & "的密码信息"
	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 &""&htmlencode(username)&"，您好：<br><br>"
	mailbody=mailbody &"欢迎您使用本交友系统的密码遗忘功能，<b>假如您不希望更改您的密码，请不要点击下面的激活连接</b>。<br>"
	mailbody=mailbody &"下面是您的密码激活连接，直接将下面的连接地址拷贝到您的浏览器地址并打开就可以将您的新密码激活：<br>"
	mailbody=mailbody &"<a href=http://"&request.servervariables("server_name")&replace(request.servervariables("script_name"),"lostpass.asp","")&"activepass.asp?username="&htmlencode(username)&"&pass="&password&"&repass="&repassword&"&answer="&answer&">http://"&request.servervariables("server_name")&replace(request.servervariables("script_name"),"lostpass.asp","")&"activepass.asp?username="&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 & Copyright & " &nbsp;&nbsp; " & Versions

	select case Mailtype
	case 0
	sendmsg="由于系统错误，给您发送的密码资料未成功。请点击右边的连接将您的密码激活：<a href=http://"&request.servervariables("server_name")&replace(request.servervariables("script_name"),"lostpass.asp","")&"activepass.asp?username="&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"),"lostpass.asp","")&"activepass.asp?username="&htmlencode(username)&"&pass="&password&"&repass="&repassword&"><B>激活密码</B></a>"
	end select
end sub

%>