$a === $b Identical *TRUE* if $a is equal to $b, and they are of the same type. (PHP 4 only)



Jonathan Wilkes wrote:

That's not his problem, he is using "===" euality check which just checks
the "type" of data, hence his code is returning TRUE for every item in the
array.

cheers,
Jonathan
        
-----Original Message-----
From: Philip Olson [mailto:[EMAIL PROTECTED]
Sent: 27 May 2003 17:03
To: Jason Lange
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Validation function doesn't work (sort of...)



When you found success in the loop you really should
end the loop otherwise it will keep checking and will
yield results as you describe.  For example:

while (1) {
   if (something) {
       $foo = true;
       break;
   } else {
       $foo = false;
   }
}

When $foo = true, the loop ends, and $foo will indeed
equal true. Although in your code below I see no need
to even define $retVal, just return true. If the loop never ends up returning true ... you know to return false.


while (1) {
if (something) {
return true;
}
}
return false;


Regards,
Philip



On Tue, 27 May 2003, Jason Lange wrote:



Hello all,

I've created this nice validation function which compares a submitted username and password to an array of acceptable values. However, at the moment it will only match the *last* key in the array. Even when I /*know*/ that I typed in the correct values (typed them in Notepad and copied and pasted them into the form) it still doesn't work. I realize this isn't the *most secure* way to do it, but it should be adaquate for what the purpose. No /really/ sensitive information is being hidden.

<?php
function _validateLogin($uploadedUser, $uploadedPass)
{
$md5 = md5('iseeYou'); // create the MD5 salt for crypt()
// array of valid users
$validUser[0] = crypt('user1', $md5);
$validUser[1] = crypt('user2', $md5);
$validUser[2] = crypt('user3', $md5);


       // array of valid passwords
       $validPass[0] = crypt('pass1', $md5);
       $validPass[1] = crypt('pass2', $md5);
       $validPass[2] = crypt('pass3', $md5);

$cryptUser = crypt($upUser, $md5); // crypt(ed) username for validation
$cryptPass = crypt($upPass, $md5); // crypt(ed) password for validation


$vCount = count($validUser); // get number of valid usernames
// loop through results - if BOTH username & password match return TRUE
// otherwise return FALSE
for ($i = 0; $i < $vCount; ++$i) {
if (($cryptUser === $validUser[$i]) &&
($cryptPass === $validPass[$i])) {
$retVal = true;
} else {
$retVal = false;
}
}
return $retVal; // return true if valid false otherwise
}
?>


Thanks in advance for your help!
Jason











--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to