Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a user password in a Access Database using ASP?

Status
Not open for further replies.

tjacoby

IS-IT--Management
Mar 21, 2002
6
0
0
US
Hello Everyone,

I currently have an ASP page setup to where an authorized user can login and view information from an Access Database. Once the user is logged in, I would like to have an option for that user to be able to update/change their current password. How would/should I go about doing this? Any and all help is welcomed. :)

Travis
 
It is so simple.
Just take him to the Change Password page.
Show (or print) his login name.Below provide 2 text boxes with type password.One for password and the other for confirm password.
Now thriugh javascript check the 2 passwords and give necessary validations whetever you want.
Now just submit it with a button and UPDATE it in database on the same page or wherever you submit the page.

You are Done ! So simple !! Rushi Shroff Rushi@emqube.com
"Life is beautiful."
 
Might anyone have sample code for doing this?

Travis
 
Here ya go:

NOTE1: It's in Javascript, but should give you some ideas even if you use VBScript

NOTE2: I hope my sourcecode is not going to get interpreted as HTML...


<%@ Language=JavaScript %>
<!--#include virtual=&quot;/include/adojavas.inc&quot;-->

<%
// if username is already taken, page create2
// will redirect back to this page. In this case,
// the following variable will be passed:
var uidExists = String(Request.QueryString(&quot;exists&quot;)) == 1;
%>
<script language=&quot;Javascript&quot;>
<!--
var alertString = &quot; \nThe following fields are either left blank or are improperly filled out: &quot;

//Check if name field is filled out
function validateForm()
{
var validationSuccess = true;
/***********************************************
********START VARIABLE DECLARATION BLOCK********
***********************************************/
var username = String(document.securityForm.resUsername.value);
var password = String(document.securityForm.resPassword.value);
var password1 = document.securityForm.resPassword1.value;
/***********************************************
*********END VARIABLE DECLARATION BLOCK*********
***********************************************/
if (isWhitespace(username) || !isAlphanumeric(username))
{
alertString += &quot;\n\n * Username (Should be letters and digits, 5-20 characters)&quot;;
validationSuccess = false;
}
else
{
if (username.length < 5)
{
alertString += &quot;\n\n * Username (It is shorter than 5 characters)&quot;;
validationSuccess = false;
}
}

if (password == password1)
{
if (isWhitespace(password) || !isAlphanumeric(password))
{
alertString += &quot;\n\n * Password (Should be letters and digits, 6-20 characters)&quot;;
validationSuccess = false;
document.securityForm.resPassword.value = &quot;&quot;;
document.securityForm.resPassword1.value = &quot;&quot;;

}
else
{
if (password.length < 6)
{
alertString += &quot;\n\n * Password (It is shorter than 6 characters)&quot;;
validationSuccess = false;
}
}
}
else
{
alertString += &quot;\n\n * Password (Should be letters and digits, 6-20 characters)&quot;;
validationSuccess = false;
}

if (validationSuccess)
{
return true;
}
else
{
alert(alertString);
alertString = &quot; \nThe following fields are either left blank or are improperly filled out: &quot;
return false;
}

} //end validateForm()
//-->
</script>

</head>
<body>

<%
//These values are available when page is submitted into itself
var resUsername = String(Request.Form(&quot;resUsername&quot;));
var resPassword = String(Request.Form(&quot;resPassword&quot;));

var connTviDB = Server.CreateObject(&quot;ADODB.Connection&quot;);
var rsResume = Server.CreateObject(&quot;ADODB.Recordset&quot;);

if (resUsername != &quot;undefined&quot;)
{
//check if username exists
sqlQuery = &quot;SELECT 'True' FROM members &quot;;
sqlQuery += &quot;WHERE resUsername = '&quot; + resUsername + &quot;' &quot;;
sqlQuery += &quot;AND memberID <> &quot; + [memberID];

connTviDB.Open(Application(&quot;tviConnStr&quot;),Application(&quot;sqlUname&quot;),Application(&quot;sqlPwd&quot;));
rsResume.Open(sqlQuery,connTviDB,adOpenForwardOnly,adLockReadOnly);
var unameExists = Boolean(!rsResume.EOF);

connTviDB.Close();
rsResume = null;

/***********************
**RESPONSE BLOCK START**
***********************/

var problemStr = &quot;<table width=440 bgcolor=#99cccc border=1 bordercolor=red cellpadding=6 cellspacing=0><tr><td><p><font color=red><b><img src='/folio/images/alert.gif' width=15 height=50 border=0 align=left hspace=10>&quot;;
problemStr += &quot;The update of username and password has failed. The username is already taken. Please try another one or just leave your old username unchanged.</b></font></td></tr></table><br><br>&quot;;

/***********************
***RESPONSE BLOCK END***
***********************/

if (unameExists)
{
Response.Write(problemStr);
}
else
{
sqlQuery = &quot;UPDATE members &quot;;
sqlQuery += &quot;SET resUsername = '&quot; + resUsername + &quot;', &quot;;
sqlQuery += &quot;resPassword = '&quot; + resPassword + &quot;' &quot;;
sqlQuery += &quot;WHERE memberID = &quot; + [memberID];

connTviDB.Open(Application(&quot;tviConnStr&quot;),Application(&quot;sqlUname&quot;),Application(&quot;sqlPwd&quot;));
connTviDB.Execute(sqlQuery);
connTviDB.Close();
connTviDB = null;
Response.Redirect(&quot;editResume.asp?call=a1s&quot;);
}

} //end if (resUsername != &quot;undefined&quot;)

%>

<form name=&quot;securityForm&quot; id=&quot;securityForm&quot; action=&quot;thisPage.asp&quot; method=&quot;post&quot; onSubmit=&quot;return validateForm();&quot;>
<table border=&quot;0&quot; cellPadding=&quot;5&quot; cellSpacing=&quot;0&quot; width=&quot;640&quot;>
<tr><td colspan=&quot;2&quot; bgcolor=&quot;#99cccc&quot;><p><b>CHANGE LOGIN INFO</b><br>
<INPUT id=submit1 name=submit1 type=submit value=&quot;Save Changes&quot; class=button>
<INPUT id=reset1 name=reset1 type=reset value=&quot;Reset Form&quot; class=button>
</p>
</td></tr>
<tr>
<td width=&quot;100&quot;><p>Username:</td>
<td width=&quot;540&quot;><p class=&quot;small&quot;><input id=&quot;resUsername&quot; name=&quot;resUsername&quot; maxlength=&quot;20&quot;>     (5 to 20
characters)</td>
</tr>
<tr>
<td><p>Password:</td>
<td><p class=&quot;small&quot;><input id=&quot;resPassword&quot; name=&quot;resPassword&quot; type=&quot;password&quot; maxlength=&quot;50&quot;>     (6 to 20 characters)</td>
</tr>
<tr>
<td><p>Retype Password</td>
<td><input id=&quot;resPassword1&quot; name=&quot;resPassword1&quot; type=&quot;password&quot; maxlength=&quot;50&quot;></td>
</tr>
</table>
</form>

</body>
</html>


Enjoy :) <Dmitriy>
dbrom@crosswinds.net
 
here are the basics for amending a password, you will obviously have to know the users name to do this, i have presumed it is stored in a cookie :


<%
' collect the password from previous page
strPassword = trim(request(&quot;your_Password_Field&quot;))

' collect the user name from your cookie
strUsername = request.cookies(&quot;your_Username_Cookie_Name&quot;)

' now update the record that matches the username with
' the new password
sqlString = &quot;UPDATE yourTable SET &quot; &_
&quot;user_password ='&quot; & strPassword & &quot;' &quot; &_
&quot;WHERE user_name = '&quot; & strUsername& &quot;'&quot;
Connection.Execute sqlString
%>
 
Thanks for the help Dmitriy, that worked great. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top