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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password Matching and Encrypting

Status
Not open for further replies.

Sitehelp

Technical User
Feb 4, 2004
142
GB
I want the user to be able to change their password if they choose too. I can get most of it working i.e. the user enters a new password (CPassword) and then confirms their password (ConfirmPassword) but I want to have the feature where they can put in their existing password as well (called CurrentPass) and then it matches with the new password field (CPassword), if they dont match an error message is displayed. I have the following code for it but it keeps coming up with a parse error and I dont know why? Any ideas?:

if ($Cpassword != $ConfirmPassword)
{echo ("New Passwords do not match");} ?>

<?php if ($CurrentPass != $CPassword)
(echo &quot;Current and New Password dont match&quot;);) ?>

Hope this wasnt written to confusingly! Also any ideas how I encrypt them as I have tried many methods and non work, methods like MD5 etc... Thanks all!
 
On the parse error: see section 1.3 of my FAQ on debugging PHP: faq434-2999


On encrypting passwords. Generally, one doesn't encrypt passwords -- one hashes passwords. The difference being that hashes are one-way.

Use MD5 to hash the password when the password is stored. Then when a user hands your script a password, hash the password and compare the stored password hash to the hash your script just generated.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Cheers got rid of that parse error but it doesnt appear to be doing what I want, actually it doesnt appear to be doing anything at all:

<?php
if ($Cpassword != $ConfirmPassword)
{echo (&quot;New Passwords do not match&quot;);}
elseif ($CurrentPass != $CPassword)
{echo (&quot;Current and New Password dont match&quot;);}

?>

Thanks again!
 
Actually it no longer matters, cheers for the help anyway!
 
Ignore that last one thought it was working but it isnt. Ok slight change in what I want but overall I want the user to enter a password and then confirm there password underneath, if these match then it continues with submission else if it doesnt it brings up a message. One password field is called &quot;Cpassword&quot; the other is called &quot;ConfirmPassword&quot;.

if ($Cpassword != $ConfirmPassword)
{echo (&quot;New Passwords do not match&quot;);}

It doesnt do this though it just changes the password to the Cpassword on submit without checking. thanks!
 
Sorry the variables onthe webpage are:

CPassword
ConfirmPassword

They are both TEXT fields.

Within the DB the password field is also called CPassword.

Is this the correct info?
 
No not yet just plain strings I am gonna trying hashing them after I have this working! cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top