CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Validation rule for password checking (solved)

Print topic Send  topic

Author Message
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
View profile  Send private message
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
View profile  Send private message
melvyn


Posts: 333
Posted: 03/15/2010, 10:05 AM

Remember that form wil be ONLY update.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com
View profile  Send private message
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
View profile  Send private message
MichaelMcDonald

Posts: 640
Posted: 03/23/2010, 2:29 AM

Does this work with encrypted passwords?
_________________
Central Coast, NSW, Australia.

View profile  Send private message
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
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.