Password is invalid
Posted: Wed Dec 31, 2008 5:28 pm
Okay, I have some code to make sure the user is entering valid data. I have this code that checks to make sure the user only enters letters, numbers,-,_ and spaces.
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...
I echoed the password here before before the switch to make sure that was fine, and it is.
On a side note, I just realized I should allow other characters to let people make their password more secure.
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';
}