Can check user password in $_POST request

This commit is contained in:
Pierre
2018-04-18 18:49:29 +02:00
parent c5c3076c67
commit fd86f954c4
2 changed files with 49 additions and 3 deletions

View File

@ -198,6 +198,32 @@ class AccountComponent {
return CS::get()->db->addLine(self::USER_TABLE, $values);
}
/**
* Check if a password is valid for a user
*
* @param int $userID Target user ID : The ID of the user to check
* @param string $password The password to check
* @return bool TRUE if the password is valid / FALSE else
*/
public function checkUserPassword(int $userID, string $password){
//Crypt password
$password = $this->cryptPassword($password);
//Prepare request over the database
$conditions = array(
"ID" => $userID,
"password" => $password
);
$data = CS::get()->db->splitConditionsArray($conditions);
$sql_conds = "WHERE ".$data[0];
$values = $data[1];
//Perform request and return result
return CS::get()->db->count(self::USER_TABLE, $sql_conds, $values) > 0;
}
/**
* Crypt user password
*