Updating password in login script using ASP MSSQL

We will add change password feature to our login script. This page to update password is available only to successfully logged in users or members so we will keep this page inside our members only area.

Link to this change password page we will add to our top menu file. This menu.asp file is kept inside the member area and as we add different files to the member area we will be adding links inside this menu.asp file. All the files to display this menu has to include this menu.asp file. Like this

<!-- #include file ="menu.asp" --->

We will ask member to enter the new password twice and for this we will display a form. In this form we will ask the user to enter new password two times. This is a simple form and only html code is used to display this. Here is the code to display the form.

<form method=post action=pwck.asp>
<table border="0" cellspacing="0" cellpadding="0" align=center width=400>
<tr><td colspan2 align=center><b>Change Password</b></td></tr>
<tr><td>Password</td><td><input type=password name=password></tr>
<tr><td>Re-enter Password</td><td><input type=password name=password2></tr>
<tr><td colspan=2 align=center><input type=submit value=''Update Password''></td></tr>
Only characters and numbers are allowed inside password field.

Once the above form is submitted we will check the entered password for two conditions. First it should match our requirement of only number and characters of 3 to 8 char length. Second both the entered passwords should be same. For our first condition checking we will use regular expression and for second condition it is simple string matching. Here we will use two variables one for error flag and other for error message. Error flag we will set to True if any error occurs and we will add the corresponding message to error message variable. At the end if error message flag is not set to true then we will update the table with new password for the particular user id . Here is the complete code.

Dim conn,rs,SQL,RecsAffected

Set conn=Server.CreateObject("ADODB.Connection")
conn.ConnectionString = aConnectionString
Set rs =Server.CreateObject("ADODB.Recordset")

Dim password,password2,error_flag,error_msg
error_flag="False" '' Setting error flag
error_msg="" '' Error message

dim RExp : set RExp = new RegExp
with RExp
.Pattern = "^[a-zA-Z0-9]{3,8}$"
.IgnoreCase = True
.Global = True
end with

If (not (RExp.test(password) and RExp.test(password2))) then
error_msg = "<br>Please enter valid data only "
End if

If (password<>password2 ) then
error_msg = error_msg + "<br>Passwords are not matching"
End if

if error_flag="False" then
rs.open "update member set password = ''"&password&"'' where userid=''" & session("userid") &"'' ", conn
Response.Write "<br><br>Successfully changed Password "
Response.Write error_msg
End if

Set rs = Nothing
Set conn = Nothing

Number of User Comments : 1




Can you substitute for...say e-mail?

Post your comments , suggestion , error , requirements etc here .

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer