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