[RESOLVED]Not Giving Correct Results
Posted: Tue Oct 08, 2013 9:54 pm
I made a login checking function:
However it doesn't give the correct result. If i enter an invalid username it returns false. However wither i enter a correct password or incorrect password it returns true. The only thing i can think of is:
which to me looks ok. Any assistance in this matter would be greatly appreciated.
Sincerely,
Aleeious
Update: tried the following code to no success
Update 2: did some debugging and both the result and user input password hash is returning results.Still no success or idea on why it's not working.
Code: Select all
/**
* checks the users login credital
* @param $username username to check
* @param $password user password to check
* @return true if login is successful otherwise false
*/
public function checkLogin($username, $password, $rounds = 12)
{
// generate the hash of the password
$hashedpassword = $this->generateHash($password);
// prepare the sql statement
$statement = $this->db->prepare('SELECT password FROM ' . TABLE_USERS . ' WHERE USERNAME = ? LIMIT 1');
// bing the variables
$statement->bind_param('s', $username);
// if the statement executed successfully
if ($statement->execute())
{
// get the number of results
$statement->bind_result($result);
// fetch the results
$statement->fetch();
// if a result exists
if($result)
{
// if the password matches
if($hashedpassword == crypt($password, $result))
{
// return true
return true;
}
// otherwise the password is incorrect
else
{
// return false
return false;
}
// otherwise return false
return false;
}
}
}
Code: Select all
f(crypt($password, $hashedpassword) == $hashedpassword)
Sincerely,
Aleeious
Update: tried the following code to no success
Code: Select all
if(substr($passwordhash, 0, 60) == crypt($password, "$2a$" . $rounds . substr($result, 60)))
$2a$12$dCLag3R4dIhSwDKpyGufQ.zZt8M8MFOx0V5q4ceaGVeiLA8XbjoFC
$2a$12$IjT1rMfjAc4daYcbapgteemWvgy.ADmBY1djB8JPaWsjSO2bFx0nK