2012-08-16 11:30:35 +00:00
|
|
|
<?php
|
|
|
|
class Auth_Base {
|
2013-04-18 11:36:54 +00:00
|
|
|
private $dbh;
|
2017-12-01 14:40:53 +00:00
|
|
|
private $pdo;
|
2013-04-18 11:36:54 +00:00
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
$this->dbh = Db::get();
|
2017-12-01 14:40:53 +00:00
|
|
|
$this->pdo = Db::pdo();
|
2013-04-18 11:36:54 +00:00
|
|
|
}
|
|
|
|
|
2017-04-26 12:29:22 +00:00
|
|
|
/**
|
|
|
|
* @SuppressWarnings(unused)
|
|
|
|
*/
|
2012-09-04 08:46:08 +00:00
|
|
|
function check_password($owner_uid, $password) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-26 12:29:22 +00:00
|
|
|
/**
|
|
|
|
* @SuppressWarnings(unused)
|
|
|
|
*/
|
2012-08-16 11:30:35 +00:00
|
|
|
function authenticate($login, $password) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auto-creates specified user if allowed by system configuration
|
|
|
|
// Can be used instead of find_user_by_login() by external auth modules
|
2013-05-07 08:36:09 +00:00
|
|
|
function auto_create_user($login, $password = false) {
|
2012-08-16 11:30:35 +00:00
|
|
|
if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) {
|
|
|
|
$user_id = $this->find_user_by_login($login);
|
|
|
|
|
2013-05-07 08:36:09 +00:00
|
|
|
if (!$password) $password = make_password();
|
|
|
|
|
2012-08-16 11:30:35 +00:00
|
|
|
if (!$user_id) {
|
|
|
|
$salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
|
|
|
|
$pwd_hash = encrypt_password($password, $salt, true);
|
|
|
|
|
2017-12-01 14:40:53 +00:00
|
|
|
$sth = $this->pdo->prepare("INSERT INTO ttrss_users
|
2012-08-16 11:30:35 +00:00
|
|
|
(login,access_level,last_login,created,pwd_hash,salt)
|
2017-12-01 14:40:53 +00:00
|
|
|
VALUES (?, 0, null, NOW(), ?,?)");
|
|
|
|
$sth->execute([$login, $pwd_hash, $salt]);
|
2012-08-16 11:30:35 +00:00
|
|
|
|
|
|
|
return $this->find_user_by_login($login);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return $user_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-16 11:38:33 +00:00
|
|
|
return $this->find_user_by_login($login);
|
2012-08-16 11:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function find_user_by_login($login) {
|
2017-12-01 14:40:53 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE
|
|
|
|
login = ?");
|
|
|
|
$sth->execute([$login]);
|
2012-08-16 11:30:35 +00:00
|
|
|
|
2017-12-01 14:40:53 +00:00
|
|
|
if ($row = $sth->fetch()) {
|
|
|
|
return $row["id"];
|
2012-08-16 11:30:35 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|