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

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....
jasocke2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dgrafxCommented:
<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>
0
jasocke2Author 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>
0
dgrafxCommented:
<cfif form.password neq form.verify>
<script>
alert("Your new passwords dont match, please try again!!")
history.go(-1)
</script>
<cfabort>
</cfif>
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

jasocke2Author 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
0
dgrafxCommented:
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#">
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jasocke2Author 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...
0
jasocke2Author Commented:
if you put two non matching new passwords the error box comes up then...
many thanks..
James
0
dgrafxCommented:
my solution should work - thanks ...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.