We help IT Professionals succeed at work.

Add a feature- Password change once logged in...

jasocke2
jasocke2 asked
on
Medium Priority
229 Views
Last Modified: 2013-12-24
Hi,

How would I go about adding a feature in the 'members' area of my website which would allow a member to change their current password,
so there would be a box for their username, then old password, new password and verify new password.
Many thanks....
Comment
Watch Question

CERTIFIED EXPERT

Commented:
<cfif isDefined("form.fieldnames")>
<cfif form.password neq form.verify>
Do a script telling that passwords do not match and send back to form
<cfabort>
</cfif>

<CFQUERY datasource="#Request.Datasource#">
Update YourTable
SET Password = '#form.password#'
WHERE UserID = '#session.UserID#' <!--- or whatever your unique id is --->
and Password = '#form.oldpassword#'
</CFQUERY>            
</cfif>

<CFQUERY datasource="#Request.Datasource#" name="getUser">
Select fields
From YourTable
WHERE UserID = '#session.UserID#' <!--- or whatever your unique id is --->
</CFQUERY>      
      
<cfoutput query="getUser">
<FORM ACTION="thispage" METHOD="post">
Current Password<br>
<input type="password" name="oldpassword" value="#password#"><br><br>
New Password<br>
<input type="password" name="password" value=""><br><br>
Verify New Password<br>
<input type="password" name="verify" value=""><br><br>
</FORM>
</cfoutput>

Author

Commented:
Hi,

All that works fine!I've just changed it around abit so you put your user_id in and put your old password in, then your new one....

But I need abit of code that a message comes up if the user_ID and oldpassword dont match...

any ideas?

Thanks...
below is a cut down version of the code!!

<cfif isDefined("form.fieldnames")>
<cfif form.password neq form.verify>
Your new passwords dont match, please try again!!
<cfabort>
</cfif>

<CFQUERY datasource="jasvasquez-access">
Update users
SET Password = '#form.password#'
WHERE User_ID = '#form.User_ID#'
and Password = '#form.oldpassword#'
</CFQUERY>
</cfif>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
Updated
</body>
</html>
CERTIFIED EXPERT

Commented:
<cfif form.password neq form.verify>
<script>
alert("Your new passwords dont match, please try again!!")
history.go(-1)
</script>
<cfabort>
</cfif>

Author

Commented:
thanks... Ive put that in but that isn't what I meant sorry!!

I need an error messgae like that but checks that the username and password are right, so if the username is test and the password is test1 but the user puts test2 as the password an error message comes up!!
Thanks
CERTIFIED EXPERT
Commented:
In the update query - you'll see the code:
and Password = '#form.oldpassword#'
which requires the old password to be correct

If you need an alert then add another form field and use code below.
You'll then need to change form.oldpassword to listlast(form.oldpassword) in other areas of your code

<cfif listfirst(form.oldpassword) neq listlast(form.oldpassword)>
<script>
alert("Your existing password is incorrect!")
history.go(-1)
</script>
<cfabort>
</cfif>
Existing Password
<input type="hidden" name="oldpassword" value="#password#">
<input type="password" name="oldpassword" value="#password#">

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
hi,
 thanks!!
almost got it to work....
but if you put a different old password a messgae box doesnt pop up, it says 'updated' but doesnt actually update it...

this is my first bit of code for the input page...

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<FORM ACTION="changepw2.cfm" METHOD="post">
  <p>User ID <br>
    <input type="text" name="user_ID" value="">
</p>
  <p>Current Password<br>
      <input type="password" name="oldpassword" value="">
      <br>
      <br>
    New Password<br>
    <input type="password" name="password" value="">
    <br>
    <br>
    Verify New Password<br>
    <input type="password" name="verify" value="">
    <br>
    <br>
    <input name="submit" type="submit" value="submit">
    </p>
  </FORM>
</body>
</html>
 
.................................................... and this is the changepw2.cfm

<cfif listlast(form.password) neq form.verify>
<script>
alert("Your new passwords dont match, please try again!!")
history.go(-1)
</script>
<cfabort>
<cfif listfirst(form.oldpassword) neq listlast(form.oldpassword)>
<script>
alert("Your existing password is incorrect!")
history.go(-1)
</script>
<cfabort>
<CFQUERY datasource="jasvasquez-access">
Update users
SET Password = listlast('#form.password#')
WHERE User_ID = '#form.User_ID#'
and Password = '#form.oldpassword#'
</CFQUERY>
</cfif>
</cfif>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
Updated
</body>
</html>

sorry for all the questions!!
Thanks...
James
...the points will be comming your way...

Author

Commented:
if you put two non matching new passwords the error box comes up then...
many thanks..
James
CERTIFIED EXPERT

Commented:
my solution should work - thanks ...
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.