Auth Db: use helper methods to retrieve data instead of FPDO raw methods

This commit is contained in:
Benjamin Renard 2024-02-04 11:02:55 +01:00
parent dbf5b0a54c
commit 20461e3e47
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -86,13 +86,11 @@ class Db extends Backend {
public static function get_user($username) {
self :: connect();
try {
$query = self :: $class :: $fpdo -> from(self :: $users_table)
-> select(null)
-> select(self :: $exposed_fields)
-> where(self :: $username_field, $username);
$result = $query -> execute();
$info = $result -> fetch();
$info = self :: $class :: get_one(
self :: $users_table,
[self :: $username_field => $username],
self :: $exposed_fields
);
if ($info === false)
return null;
return new User($username, '\\EesyPHP\\Auth\\Db', $info);
@ -112,16 +110,14 @@ class Db extends Backend {
public static function check_password($user, $password) {
self :: connect();
try {
$query = self :: $class :: $fpdo -> from(self :: $users_table)
-> select(null)
-> select(self :: $password_field)
-> where(self :: $username_field, $user->username);
$result = $query -> execute();
$info = $result -> fetch();
$info = self :: $class :: get_one(
self :: $users_table,
[self :: $username_field => $user->username],
[self :: $password_field]
);
if ($info === false)
return false;
return password_verify($password, $info['password']);
return password_verify($password, $info[self :: $password_field]);
}
catch (Exception $e) {
Log :: error("Error retrieving user %s password from database: %s", $user, $e->getMessage());