<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns="<head runat="server"> function checkNewPwd(pwd) function checkConfirmNewPwd(pwd) function validatePwd(pwd) function updateNewPwd() </script> using System; public partial class _Default : System.Web.UI.Page } <%@ WebHandler Language="C#" Class="CheckPwd" %> using System; public class CheckPwd : IHttpHandler, System.Web.SessionState.IRequiresSessionState public void ProcessRequest(HttpContext context) string userId = context.Session["UserId"].ToString(); public bool IsReusable } <%@ WebHandler Language="C#" Class="UpdatePwd" %> using System; public class UpdatePwd : IHttpHandler, System.Web.SessionState.IRequiresSessionState public void ProcessRequest(HttpContext context) public bool IsReusable }
<title>修改密碼</title>
<script type="text/javascript" src="JS/jquery-1.4.2.min.js"></script><%--添加對(duì)JQuery類庫(kù)的引用--%>
<script type="text/javascript">
var oldPwdPass=false;
var newPwdPass=false;
var newPwd;
function checkOldPwd(pwd)
{
if(pwd==""||pwd==null)
{
document.getElementById("get_old_passwordMsg").innerHTML="舊密碼不能為空!";
return false;
}
else if(validatePwd(pwd))
{
document.getElementById("get_old_passwordMsg").innerHTML="舊密碼只能是6-16位的字母或數(shù)字!";
return false;
}
else
{
document.getElementById("get_old_passwordMsg").innerHTML="";
//下面自動(dòng)調(diào)用引用的JQuery類庫(kù)
$.ajax({
type:"get",
轉(zhuǎn)到一般處理程序
data:{"Pwd":pwd,"random":Math.random()},
success:function(data)
{
if(data=="true")
{
oldPwdPass=true;
return true;
}
else
{
document.getElementById("get_old_passwordMsg").innerHTML="舊密碼輸入錯(cuò)誤!";
document.getElementById("get_old_password").value="";
return false;
}
}
});
}
}
{
if(pwd==""||pwd==null)
{
document.getElementById("get_new_passwordMsg").innerHTML="新密碼不能為空!";
return false;
}
else if(validatePwd(pwd))
{
document.getElementById("get_new_passwordMsg").innerHTML="新密碼只能是6-16位的字母或數(shù)字!";
return false;
}
else
{
newPwd=pwd;
document.getElementById("get_new_passwordMsg").innerHTML="";
return true;
}
}
{
if(pwd==""||pwd==null)
{
document.getElementById("confirm_new_passwordMsg").innerHTML="確認(rèn)新密碼不能為空!";
return false;
}
else if(validatePwd(pwd))
{
document.getElementById("confirm_new_passwordMsg").innerHTML="確認(rèn)新密碼只能是6-16位的字母或數(shù)字!";
return false;
}
else
{
document.getElementById("confirm_new_passwordMsg").innerHTML="";
if(newPwd!=""&&newPwd!=null)
{
if(newPwd!=pwd)
{
document.getElementById("confirm_new_passwordMsg").innerHTML="確認(rèn)新密碼與新密碼不一致!";
document.getElementById("confirm_new_password").value="";
return false;
}
else
{
document.getElementById("confirm_new_passwordMsg").innerHTML="";
newPwdPass=true;
return true;
}
}
else
{
document.getElementById("get_new_passwordMsg").innerHTML="新密碼不能為空!";
return false;
}
}
}
{
regularPaw=/^[\dA-Za-z(!@#$%&)]{6,16}$/;
if(regularPaw.test(pwd)==false)
{
return true;
}
else
{
return false;
}
}
{
if(oldPwdPass&&newPwdPass)
{
oldPwdPass=false;
newPwdPass=false;
$.ajax({
type:"get",
轉(zhuǎn)到一般處理程序
data:{"NewPwd":newPwd,"random":Math.random()},
success:function(data)
{
if(data=="true")
{
document.getElementById("get_old_password").value="";
document.getElementById("get_new_password").value="";
document.getElementById("confirm_new_password").value="";
alert("密碼修改成功!");
}
else
{
document.getElementById("get_old_password").value="";
document.getElementById("get_new_password").value="";
document.getElementById("confirm_new_password").value="";
alert("密碼修改失敗,請(qǐng)重新修改!");
}
}
});
}
else
{
alert("請(qǐng)?zhí)顚?xiě)完整修改密碼所必需的信息!");
}
return false;
}
</head>
<body>
<form id="formBody" runat="server">
<div>
<div>
<div>
<b id="psnB1"></b><h3>修改密碼:</h3>
</div>
<div class="ln-thin ln-c-mid"></div>
<div style="height:1px; background-color:White"></div>
<table id="psnB1Table">
<tbody>
<tr>
<th><label for="get_cust_name">您的會(huì)員登錄名是:</label></th>
<td>
<asp:Label ID="get_cust_name" runat="server" Text="Label" Font-Bold="True"></asp:Label>
</td>
</tr>
<tr>
<th><label for="get_old_password">舊密碼:</label></th>
<td>
<input id="get_old_password" type="password" onblur="checkOldPwd(this.value);" CssClass="required oldpawcl"/> <span style="color:Red; font-size:14px">*</span>
<label id="get_old_passwordMsg" class="errorMsg"></label>
</td>
</tr>
<tr>
<th><label for="get_new_password">新密碼:</label></th>
<td>
<input id="get_new_password" type="password" onblur="checkNewPwd(this.value);" CssClass="required newpawcl"/> <span style="color:Red; font-size:14px">*</span>
<label id="get_new_passwordMsg" class="errorMsg"></label>
</td>
</tr>
<tr>
<th><label for="confirm_new_password">確認(rèn)新密碼:</label></th>
<td>
<input id="confirm_new_password" type="password" onblur="checkConfirmNewPwd(this.value);" CssClass="required cfnewpawcl"/> <span style="color:Red; font-size:14px">*</span>
<label id="confirm_new_passwordMsg" class="errorMsg"></label>
</td>
</tr>
</tbody>
</table>
</div>
<div style="margin-bottom:-1px">
<div class="ln-thin ln-c-mid"></div>
<div style="height:1px; background-color:White"></div>
<div id="psnTable4"></div>
</div>
<table>
<tbody>
<tr>
<th>
</th>
<td>
<asp:Button ID="Finish" CssClass="Button" runat="server" Text="修 改" OnClientClick="javascript:return updateNewPwd();" />
</td>
</tr>
</tbody>
</table>
</div>
</form>
</body>
</html>
2.后臺(tái)代碼頁(yè)(Default.aspx.cs):
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["UserId"] = "001";
Session["UserName"] = "HEHE";
}
get_cust_name.Text = Session["UserName"].ToString();//獲取當(dāng)前登錄用戶的Session中的UserName
}
3.一般處理程序1(CheckPwd.ashx):
using System.Web;
{
{
context.Response.ContentType = "text/plain";
string pwd = context.Request["Pwd"];
string dbPwd = "123456";//演示密碼
//string dbPwd=UpdatePasswordService.GetDbPwd(userId);//自己寫(xiě)的類中的方法,從數(shù)據(jù)庫(kù)中取出密碼。
if (pwd == dbPwd)
{
context.Response.Write("true");
}
else
{
context.Response.Write("false");
}
}
{
get
{
return false;
}
}
4.一般處理程序2(UpdatePwd.ashx):
using System.Web;
{
{
context.Response.ContentType = "text/plain";
string newPwd = context.Request["NewPwd"];
string userId = context.Session["UserId"].ToString();
bool result = true;//演示結(jié)果
//bool result = UpdatePasswordService.UpdatePwd(userId, encryptPwd);//自己寫(xiě)的類中的方法,更新密碼并返回是否成功。
if (result)
{
context.Response.Write("true");
}
else
{
context.Response.Write("false");
}
}
{
get
{
return false;
}
}
聯(lián)系客服