Classic ASP code for Change of Password. It is a single ASP file. Javascript for validation included.
===================================================================
<%
Set MyConn =Server.CreateObject("ADODB.Connection")
MyConn.open="provider=MSDAORA;data source=xxx; user id=yyy;password=zzzz"
%>
<%
'NOTE USER_ID AND USER_GROUP SHOULD BE IN SESSIONS
THIS_FILE_NAME="user_change_password.asp"
SESSION_USER_ID="staff_no"
SESSION_GROUP_ID="user_group"
If Session(SESSION_USER_ID)="" or Session(SESSION_GROUP_ID)="" Then
Response.Redirect("../logout.asp")
End If
If Request("job")="change_password" Then
SESSION_USER_ID_VALUE=Session(SESSION_USER_ID)
old_password=trim(Request("old_password"))
new_password=trim(Request("new_password"))
Set ObjRsOld=Myconn.Execute("select * from table1 where staff_no='" & SESSION_USER_ID_VALUE & "' and password='" & old_password & "' and location_id='" & session("location_id") & "'")
If ObjRsOld.EOF then
Response.Redirect(THIS_FILE_NAME &"?result=Incorrect Old Password. Please try again")
End If
sql="update oe_user_master set password='" & new_password & "' where staff_no='" & SESSION_USER_ID_VALUE & "' and password='" & old_password & "' and location_id='" & session("location_id") & "'"
'response.write(sql)
Myconn.execute(sql)
Myconn.close
Set Myconn=Nothing
Response.redirect(THIS_FILE_NAME &"?result=Password Changed SUCCESSFULLY")
End If
%>
<html>
<head>
<style>
body{font:normal 10px verdana,arial ;color:#336699;}
</style>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Change Password</title>
<script language="javascript">
function validate()
{
var pass=document.f1.new_password.value;
var ValidateDigits = /[^0-9]/g;
var ValidateSpChar = /[a-zA-Z0-9]/g;
var digitString = pass.replace(ValidateDigits , "");
var specialString =pass.replace(ValidateSpChar, "");
if (document.f1.old_password.value==""){
alert("Enter old password");
document.f1.old_password.focus();
return false;
}
if (document.f1.new_password.value==""){
alert("Enter New password");
document.f1.new_password.focus();
return false;
}
if (pass.length< 8){
alert("Password should be of minimum 8 characaters");
document.f1.new_password.focus();
return false;
}
if(specialString < 1)
{
alert("Passwords must include at least 1 special (#,@,&,$ etc) characters");
document.f1.new_password.focus();
return false;
}
if(digitString < 1)
{
alert("Passwords must include at least 1 numeric characters");
document.f1.new_password.focus();
return false;
}
if (document.f1.confirm_password.value==""){
alert("Enter Confirm password");
document.f1.confirm_password.focus();
return false;
}
if (document.f1.new_password.value != document.f1.confirm_password.value){
alert("New password and Confirm password not same. Please try again");
document.f1.confirm_password.focus();
return false;
}
return true;
}
</script>
<!--#####alert message starts-->
<script>
window.onload=function()
{alert_result_msg();}
</script>
<script language="javascript">
function alert_result_msg(){
if (FormResultMsg.resultMsg.value !=""){
alert(FormResultMsg.resultMsg.value);
}
}
</script>
<form name="FormResultMsg">
<input type="hidden" name="resultMsg" value="<%=request("result")%>">
</form>
<!--#####alert message ends-->
</head>
<body >
<table width=100% >
<tr >
<Td align=right>
<button onClick="javascript:window.close()">Close Window</button>
</Td></tr>
</table>
<br>
<br>
<br>
<form name="f1" action="<%=THIS_FILE_NAME%>" onSubmit="return validate()" method="post">
<input type="hidden" name="job" value="change_password" />
<table border="0" align=center cellpadding="2" cellspacing="0" style="margin:20px;border-style:inset; border-color:#336699;">
<tr >
<td colspan=2 align=center >
Your User ID :<%=session("staff_no")%>
<br>
Your User Group:<%=session("user_group")%>
<br>
<br>
</td>
</tr>
<td width="212" align="right" >
Enter Old Password :
</td>
<td width="152" >
<input type="password" name="old_password" size="25" >
</td>
</tr>
<tr>
<td width="212" align="right" >
Enter New password :
</td>
<td >
<input type="password" name="new_password" size="25" >
</td>
</tr>
<tr>
<td width="212" align="right" >
Retype New Password :
</td>
<td >
<input type="password" name="confirm_password" size="25" >
</td>
</tr>
<tr >
<td colspan="2" > <div align="center">
<input type="submit" value="Submit" style="font:bold 20px arial;">
</div></td>
</tr>
<tr>
<td colspan=2 align=center style="font:normal 9px verdana,arial">
Password
should contain minimum <b>EIGHT</b> characters with
<br>
atleast <b>ONE NUMERIC</b> &
<b>ONE SPECIAL</b> character
</td>
</tr>
</table>
</form>
<div style="color:white">
<%
for each x in session.Contents
response.write(x & session.contents(x))
next
%>
</div>
</body>
</html>
No comments:
Post a Comment