...

View Full Version : compare two strings are the same but not as a value



needsomehelp
02-27-2010, 04:44 PM
I am trying to get my script to check if both password fields have the same content but using the standard

if ($pw1 = $pw2) { //do something } else { // show error message }

does not work when a password like

00000 and 0000000000000 is used as these are both the same in value but not in content.

how do i correct and safely check these are the same for my sign up page.


EDIT

i have just tried...

if (strcmp($pw1,$pw2) == 0) { //do something } else { // show error message }

but this too does the same, it uses the strings as values.

masterofollies
02-27-2010, 04:51 PM
I haven't done this before, but it should be this.



$pw1 = $_POST['password1'];
$pw2 = $_POST['password2'];

if ($pw1 != $pw2) {
//Show error
}
else {
//Process
}

needsomehelp
02-27-2010, 05:26 PM
I haven't done this before, but it should be this.



$pw1 = $_POST['password1'];
$pw2 = $_POST['password2'];

if ($pw1 != $pw2) {
//Show error
}
else {
//Process
}

i have tried this already in my original code!!

if the user was to enter say

00000 zeros in the first
and

0000000000 loads of zeros in the second

if ($pw1 != $pw2) {

would allow this as valid even though the two 'strings' are not the same

it is checking them as values not strings.

MattF
02-27-2010, 05:28 PM
if ($pw1 !== $pw2) {

koko5
02-27-2010, 05:30 PM
Hi,Try comparison of value and type === , !==

Edit: MattF was faster :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum