<!--#include file="inc/conn.asp"-->
<!--#include file="inc/md5.asp"-->
<!--#include file="inc/function.asp"-->
<%
if CheckUserLogined()=False then
	response.Redirect "UserLogin.asp"
end if

dim Action,UserName,FoundErr,ErrMsg
dim OldPassword,Password,PwdConfirm
dim rsUser,sqlUser
Action=trim(request("Action"))
UserName=trim(request("UserName"))
OldPassword=trim(request("OldPassword"))
Password=trim(request("Password"))
PwdConfirm=trim(request("PwdConfirm"))
if Action="Modify" and UserName<>"" then
	Set rsUser=Server.CreateObject("Adodb.RecordSet")
	sqlUser="select * from [User] where UserName='" & UserName & "'"
	rsUser.Open sqlUser,conn,1,3
	if rsUser.bof and rsUser.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>找不到指定的用户！</li>"
	else
		if OldPassword="" then
			FoundErr=True
			ErrMsg=ErrMsg & "<br><li>请输入旧密码！</li>"
		else
			if Instr(OldPassword,"=")>0 or Instr(OldPassword,"%")>0 or Instr(OldPassword,chr(32))>0 or Instr(OldPassword,"?")>0 or Instr(OldPassword,"&")>0 or Instr(OldPassword,";")>0 or Instr(OldPassword,",")>0 or Instr(OldPassword,"'")>0 or Instr(OldPassword,",")>0 or Instr(OldPassword,chr(34))>0 or Instr(OldPassword,chr(9))>0 or Instr(OldPassword,"")>0 or Instr(OldPassword,"$")>0 then
				errmsg=errmsg+"<br><li>旧密码中含有非法字符</li>"
				founderr=true
			else
				if md5(OldPassword)<>rsUser("Password") then
					FoundErr=True
					ErrMsg=ErrMsg & "<br><li>你输入的旧密码不对，没有权限修改！</li>"
				end if
			end if
		end if
		if strLength(Password)>12 or strLength(Password)<6 then
			founderr=true
			errmsg=errmsg & "<br><li>请输入新密码(不能大于12小于6)。</li>"
		else
			if Instr(Password,"=")>0 or Instr(Password,"%")>0 or Instr(Password,chr(32))>0 or Instr(Password,"?")>0 or Instr(Password,"&")>0 or Instr(Password,";")>0 or Instr(Password,",")>0 or Instr(Password,"'")>0 or Instr(Password,",")>0 or Instr(Password,chr(34))>0 or Instr(Password,chr(9))>0 or Instr(Password,"")>0 or Instr(Password,"$")>0 then
				errmsg=errmsg+"<br><li>新密码中含有非法字符</li>"
				founderr=true
			end if
		end if
		if PwdConfirm="" then
			FoundErr=True
			ErrMsg=ErrMsg & "<br><li>请输入确认密码！</li>"
		else
			if PwdConfirm<>Password then
				FoundErr=True
				ErrMsg=ErrMsg & "<br><li>确认密码与新密码不一致！</li>"
			end if
		end if
		if FoundErr<>true then
			Password=md5(Password)
			rsUser("Password")=Password
			rsUser.update
			Response.Cookies("asp163")("Password") = PassWord
		end if
	end if
	rsUser.close
	set rsUser=nothing
	if FoundErr=True then
		call WriteErrMsg()
	else
		call WriteSuccessMsg("成功修改密码！")
	end if
else
%>
<html>
<head>
<title>修改用户密码</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<style>
<!--
body         { font-size: 10pt }
td           { font-size: 10pt }
-->
</style>

</head>
<body>
<br>
<FORM name="Form1" action="UserModifyPwd.asp" method="post">
  <table width=400 border=0 align="center" cellpadding=0 cellspacing=0 class='border' style="border-style: solid; border-width: 1">
    <TR align=center class='title'> 
      <TD height=22 colSpan=2><font class=en>修改用户密码</font></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="120" align="right">用 户 名：</TD> 
      <TD><%=Trim(Request.Cookies("asp163")("UserName"))%> <input name="UserName" type="hidden" value="<%=Trim(Request.Cookies("asp163")("UserName"))%>"></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="120" align="right">旧 密 码：</TD>
      <TD> <INPUT   type=password maxLength=16 size=30 name=OldPassword> </TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="120" align="right">新 密 码：</TD> 
      <TD> <INPUT   type=password maxLength=16 size=30 name=Password> </TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="120" align="right">确认密码：</TD>
      <TD><INPUT name=PwdConfirm   type=password id="PwdConfirm" size=30 maxLength=16> 
      </TD>
    </TR>
    <TR align="center" class="tdbg" > 
      <TD height="40" colspan="2"><input name="Action" type="hidden" id="Action" value="Modify"> 
        <input name=Submit   type=submit id="Submit" value=" 保 存 "> </TD>
    </TR>
  </TABLE>
</form>
</body>
</html>
<%
end if
call CloseConn()
%>