From ec78c923e4ec7af1ec6e8386b36dd71678be2d0b Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Tue, 2 Apr 2024 09:34:46 +0200 Subject: [PATCH] Restore checkPassword() function Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- lib/UserBackend.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/UserBackend.php b/lib/UserBackend.php index 991c8099d..0872260ce 100644 --- a/lib/UserBackend.php +++ b/lib/UserBackend.php @@ -187,6 +187,34 @@ public function implementsActions($actions) { return (bool)($availableActions & $actions); } + /** + * Check if the provided token is correct + * @param string $uid The username + * @param string $password The password + * @return string + * + * Check if the password is correct without logging in the user + * returns the user id or false + */ + public function checkPassword($uid, $password) { + $qb = $this->db->getQueryBuilder(); + $qb->select('token') + ->from('user_saml_auth_token') + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) + ->setMaxResults(1000); + $result = $qb->execute(); + $data = $result->fetchAll(); + $result->closeCursor(); + + foreach ($data as $passwords) { + if (password_verify($password, $passwords['token'])) { + return $uid; + } + } + + return false; + } + /** * delete a user * @param string $uid The username of the user to delete