diff options
Diffstat (limited to 'classes/auth/base.php')
-rw-r--r-- | classes/auth/base.php | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/classes/auth/base.php b/classes/auth/base.php index aa9d657a4..69acd0985 100644 --- a/classes/auth/base.php +++ b/classes/auth/base.php @@ -1,9 +1,9 @@ <?php class Auth_Base { - protected $link; + private $dbh; - function __construct($link) { - $this->link = $link; + function __construct() { + $this->dbh = Db::get(); } function check_password($owner_uid, $password) { @@ -16,12 +16,14 @@ class Auth_Base { // 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) { + function auto_create_user($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(); + if (!$user_id) { - $login = db_escape_string($login); + $login = $this->dbh->escape_string($login); $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); $pwd_hash = encrypt_password($password, $salt, true); @@ -29,7 +31,7 @@ class Auth_Base { (login,access_level,last_login,created,pwd_hash,salt) VALUES ('$login', 0, null, NOW(), '$pwd_hash','$salt')"; - db_query($this->link, $query); + $this->dbh->query($query); return $this->find_user_by_login($login); @@ -42,13 +44,13 @@ class Auth_Base { } function find_user_by_login($login) { - $login = db_escape_string($login); + $login = $this->dbh->escape_string($login); - $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE + $result = $this->dbh->query("SELECT id FROM ttrss_users WHERE login = '$login'"); - if (db_num_rows($result) > 0) { - return db_fetch_result($result, 0, "id"); + if ($this->dbh->num_rows($result) > 0) { + return $this->dbh->fetch_result($result, 0, "id"); } else { return false; } |