Use the old password verification function written in ajax

Source: Internet
Author: User

1 page: Set the text box of the old password as an html control. It is convenient to call javascript Functions. a div is placed next to it to display the prompt.

<Th style = "width: 60px">
Old password: </th>
<Td colspan = "3">
<Input id = "TB_OldPass" type = "password" onblur = "CheckPass ()"/>
<Div id = "Pass_Txt" style = "z-index: 101; left: 468px; width: 100px; position: absolute; top: 48px;
Height: 17px; display: none ">
</Div>

When the text box of the old password loses focus, the verification event CheckPass () is triggered ();

This function is in another js file. Do not forget to reference it on this page.

<Script language = "javascript" type = "text/javascript" src = "js/CheckPass. js"> </script>

File ChekcPass. js Code

 

Function CheckPass ()
{
// First obtain the old password characters
Var keys = document. getElementById ("TB_OldPass"). value;

// Asynchronous Data Transmission
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
Xmlhttp. onreadystatechange = statechangeLoad;
// Call the ModifyPass. aspx file to execute the background code.
Xmlhttp. open ("GET", "ModifyPass. aspx? Pass = "+ encodeURI (keys), true );
Xmlhttp. send (null );


}

Function statechangeLoad ()
{
If (xmlhttp. readystate = 4)
{
If (xmlhttp. status = 200)
{

// The password verification result is displayed on the page.
Document. getElementById ("Pass_Txt"). innerHTML = xmlhttp. responseText;
Document. getElementById ("Pass_Txt"). style. display = "";
// Determine whether the new password can be entered Based on the displayed characters.
If (document. getElementById ("Pass_Txt"). innerHTML = "the old password is successfully verified ")
{
Document. getElementById ("TB_NewPass"). readOnly = false;
Document. getElementById ("TB_NewRePass"). readOnly = false;
}
Else
{

// Directly focus on the text box of the old password, which is more user-friendly
Document. form1.TB _ OldPass. focus ();

}
}
}
}

Password verification events mainly rely on the Page_Lode event on the ModifyPass. aspx page

Protected void Page_Load (object sender, EventArgs e)
{
// Obtain the string of the passed Password
String Pass = Tools. GetMD5 (Request. QueryString ["Pass"]. ToString ());
// Obtain the ID of the current user
// String CurrentUserId = Session ["CurrentUserId"]. ToString ();
String CurrentUserId = "4 ";
// Determine whether the passed user ID and Password Match
DataSet ds = new DataSet ();
If (Business. Patient. CheckPass (Convert. ToInt32 (CurrentUserId), Pass ))
{
Response. Write ("the old password is successfully verified ");
}
Else
{
Response. Write ("failed to verify the old password ");
}
}

The password verification result is returned on this page, which is displayed on the homepage.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.