<%@ Page Language="C#" ContentType="text/html" Inherits="Ycbw.Data.OleDbClient" %>

<%@ Register TagPrefix="Rajah" TagName="Head" src="../ctrls/head.ascx" %>
<%@ Register TagPrefix="Rajah" TagName="Foot" src="../ctrls/foot.ascx" %>

<script language="c#" runat="server">

private void Page_Load(object sender,EventArgs e)
{


}

private void button_submit_click(object sender,EventArgs e)
{
	if( this.CheckUser( Session["admin"].ToString(), this.password_old.Text ) )
	{
		string password = FormsAuthentication.HashPasswordForStoringInConfigFile( this.password.Text,"MD5").ToLower();
		string confirm  = FormsAuthentication.HashPasswordForStoringInConfigFile( this.password_confirm.Text,"MD5").ToLower();
	
		if( password == confirm )
		{
			this.UpdateUser( Session["admin"].ToString(), this.password.Text);
			this.JWrite( "alert('修改密码成功!');window.close();" );
		}
		else
		{
			this.JWrite( "alert('您输入的新密码和确认密码并不相同!');history.go(-1)" );
		}
	}
	else
	{
		this.JWrite( "alert('对不起, 您输入的现用密码有误!');history.go(-1)" );
	}
}

private bool CheckUser( string username, string password )
{
	password = FormsAuthentication.HashPasswordForStoringInConfigFile(password,"MD5").ToLower();
	
	this.Fill( "Select Top 1 * From [b_admin] where username Like '"+ username +"' and password Like '"+ password +"'", "data_user" );

	if( this.Data.Tables["data_user"].Rows.Count == 1 )
		return true;
	else
		return false;
}

private void UpdateUser( string username, string password )
{
	string p = FormsAuthentication.HashPasswordForStoringInConfigFile(password,"MD5").ToLower();
	
	this.Execute( "Update [b_admin] set [password] = '"+ p +"' where [username] like '"+ Session["admin"] +"'" );
}

</script>

<Rajah:Head ID="Head" Runat="Server" />
<link href="../css/default.css" rel="stylesheet" type="text/css">
<form runat="server">
<table width="100%" align="center" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="title3">
		<div style="float:left">修改密码</div>
		<div style="float:right"></div>
	  </td>
  </tr>
</table>
<table width="100%" align="center" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	<table width="100%" border="0" align="center" cellpadding="0" cellspacing="9">
	  <tr>
		<td colspan="4" class="table3"><input type="button" onclick="history.go(-1);" value=" 返回 ">&nbsp;<asp:Button Text=" 提交 " OnClick="button_submit_click" runat="server" /></td>
	  </tr>
		<tr>
		  <td width="80" align="right">现用密码</td>
		  <td><asp:TextBox ID="password_old" CssClass="text2" runat="server" Width="200" /></td>
		  <td align="right">&nbsp;</td>
		  <td>&nbsp;</td>
		</tr>
		<tr>
		  <td width="80" align="right">新密码</td>
		  <td><asp:TextBox ID="password" CssClass="text2" runat="server" Width="200" /></td>
		  <td align="right">&nbsp;</td>
		  <td>&nbsp;</td>
		</tr>
		<tr>
		  <td width="80" align="right">确认新密码</td>
		  <td><asp:TextBox ID="password_confirm" CssClass="text2" runat="server" Width="200" /></td>
		  <td align="right">&nbsp;</td>
		  <td>&nbsp;</td>
		</tr>
		<tr>
		  <td colspan="4" class="table3"><input type="button" onclick="history.go(-1);" value=" 返回 ">&nbsp;<asp:Button Text=" 提交 " OnClick="button_submit_click" runat="server" /></td>
		  </tr>
		</table>
	</td>
  </tr>
</table>
</form>
<Rajah:Foot ID="Foot" Runat="Server" />