summaryrefslogtreecommitdiff
path: root/classes/auth
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-11 10:22:27 +0300
committerAndrew Dolgov <[email protected]>2021-02-11 10:22:27 +0300
commit09e9f34bb495b435e826bce8cf716258039d4642 (patch)
tree60cdaf053a0af182cc66002790548caf09339c25 /classes/auth
parent7af8744c856545f62a2f24fd1a700f40b90b8e37 (diff)
add UserHelper::find_user_by_login() and rewrite some user checks to invoke it instead of going through PDO
Diffstat (limited to 'classes/auth')
-rw-r--r--classes/auth/base.php27
1 files changed, 10 insertions, 17 deletions
diff --git a/classes/auth/base.php b/classes/auth/base.php
index 1d68ae537..d54e9d8a2 100644
--- a/classes/auth/base.php
+++ b/classes/auth/base.php
@@ -15,13 +15,14 @@ abstract class Auth_Base extends Plugin implements IAuthModule {
// Auto-creates specified user if allowed by system configuration
// Can be used instead of find_user_by_login() by external auth modules
- function auto_create_user($login, $password = false) {
+ function auto_create_user(string $login, $password = false) {
if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) {
- $user_id = $this->find_user_by_login($login);
-
- if (!$password) $password = make_password();
+ $user_id = UserHelper::find_user_by_login($login);
if (!$user_id) {
+
+ if (!$password) $password = make_password();
+
$salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
$pwd_hash = encrypt_password($password, $salt, true);
@@ -30,26 +31,18 @@ abstract class Auth_Base extends Plugin implements IAuthModule {
VALUES (LOWER(?), 0, null, NOW(), ?,?)");
$sth->execute([$login, $pwd_hash, $salt]);
- return $this->find_user_by_login($login);
+ return UserHelper::find_user_by_login($login);
} else {
return $user_id;
}
}
- return $this->find_user_by_login($login);
+ return UserHelper::find_user_by_login($login);
}
- function find_user_by_login($login) {
- $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE
- LOWER(login) = LOWER(?)");
- $sth->execute([$login]);
-
- if ($row = $sth->fetch()) {
- return $row["id"];
- } else {
- return false;
- }
-
+ // @deprecated
+ function find_user_by_login(string $login) {
+ return UserHelper::find_user_by_login($login);
}
}