Cleopatra
Posts: 73
|
| Posted: 03/15/2010, 7:58 AM |
|
Hi all,
I've created a page for changing the password. So basically a users can change his/her password anytime.
I have 3 fields: current password, new password, and confirm new password.
the user needs to type in all the fields.
Can anyone tell me how to compare the inserted password with the one in the db and how to compare the new password and confirm new password using the validation rule?
All help appreciated.
_________________
php newbie |
 |
 |
melvyn
Posts: 333
|
| Posted: 03/15/2010, 10:04 AM |
|
Let's assume you have your form with the following fields (textboxes):
- current_password
- password1
- password2
Remember to not point current_password to a field, set it as "code expression" instead of databaase column; password2 must point to the password field in the table. (password1 doesn't matter if point or not, let's put it as code expression too.
Well, it's a form that places a field in the database, the password field.
Place the following in event OnValidate
global $DB-YOUR-DB-CONNECTION;
// get the current *logged* user
$userid = CCGetSession("UserID");
// get the current password from the form
$password = $Container->current_password->GetValue();
// check if the current password is the correct
$thepass = CCDLookUp("COUNT(*)","users","id = '$userid' AND password = '$password'",$DB-YOUR-DB-CONNECTION);
// if incorrect fire an error (will be shown in the form's error container)
if($thepass == 0 ){
$Container->Errors->AddError("Current password incorrect.");
}
// check than password1 and password are the same, if not fire an error
if($Container->password1->GetValue() != $Container->password2->GetValue()){
$Container->Errors->AddError("New password and confirmation doesn't match.");
}
Enjoy
M.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com |
 |
 |
melvyn
Posts: 333
|
| Posted: 03/15/2010, 10:05 AM |
|
Remember that form wil be ONLY update.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com |
 |
 |
Cleopatra
Posts: 73
|
| Posted: 03/16/2010, 4:45 AM |
|
Thank you, Melvyn
The comparison of the newpassword and the confirmationpassword works perfectly. However, I'm getting an error for the comparison of the currentpassword with that of the database. I think I can figure out what it is I'm doing wrong. If it still doesn't work, I'll ask.
Thank you so much for your help.
_________________
php newbie |
 |
 |
MichaelMcDonald
Posts: 640
|
| Posted: 03/23/2010, 2:29 AM |
|
Does this work with encrypted passwords?
_________________
Central Coast, NSW, Australia.
|
 |
 |
melvyn
Posts: 333
|
| Posted: 03/23/2010, 5:11 AM |
|
Quote MichaelMcDonald:
Does this work with encrypted passwords?
If you want it encrypted then modify the line at
$password = $Container->current_password->GetValue();
$password = md5($password); // or whatever function you're using to encrypt it
Remember to encrypt the new password using your function.
M.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com |
 |
 |
|