Code: Select all
function validateTextString($text)
{
return preg_match('/^[a-zA-Z0-9\s\-_]+$/', $text) ? true : false;
}For some reason when I give it the password 'test' it fails saying that it is invalid.
EDIT, in the code below, shouldn't the code stop executing once it hits a return? Because the code below doesn't...
Code: Select all
function validatePassword($password)
{
if(!validateTextString($password))
return ERROR_PASSWORD_INVALID;
if(!checkLength($password, MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH))
return ERROR_PASSWORD_LENGTH;
return true;
}I echoed the password here before before the switch to make sure that was fine, and it is.
Code: Select all
switch(validatePassword($password))
{
case ERROR_PASSWORD_INVALID:
$error[] = 'Password is invalid';
break;
case ERROR_PASSWORD_LENGTH:
$error[] = 'Invalid password length';
break;
default:
$password = sha1($password);
// Check to see if the password is correct
if(!checkPassword($username, $password))
$error[] = 'Incorrect password';
// Check to see if the account is activated
if(!isActivated($username))
$error[] = 'Account has not been activated';
}