]>
Commit | Line | Data |
---|---|---|
0d421af8 AD |
1 | <?php |
2 | class Auth_Base { | |
8cb5c64d | 3 | private $dbh; |
c9d5c260 | 4 | private $pdo; |
8cb5c64d AD |
5 | |
6 | function __construct() { | |
7 | $this->dbh = Db::get(); | |
c9d5c260 | 8 | $this->pdo = Db::pdo(); |
8cb5c64d AD |
9 | } |
10 | ||
7b55001e AD |
11 | /** |
12 | * @SuppressWarnings(unused) | |
13 | */ | |
ec78654f AD |
14 | function check_password($owner_uid, $password) { |
15 | return false; | |
16 | } | |
17 | ||
7b55001e AD |
18 | /** |
19 | * @SuppressWarnings(unused) | |
20 | */ | |
0d421af8 AD |
21 | function authenticate($login, $password) { |
22 | return false; | |
23 | } | |
24 | ||
25 | // Auto-creates specified user if allowed by system configuration | |
26 | // Can be used instead of find_user_by_login() by external auth modules | |
ea46d90e | 27 | function auto_create_user($login, $password = false) { |
0d421af8 AD |
28 | if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) { |
29 | $user_id = $this->find_user_by_login($login); | |
30 | ||
ea46d90e AD |
31 | if (!$password) $password = make_password(); |
32 | ||
0d421af8 | 33 | if (!$user_id) { |
0d421af8 AD |
34 | $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
35 | $pwd_hash = encrypt_password($password, $salt, true); | |
36 | ||
c9d5c260 | 37 | $sth = $this->pdo->prepare("INSERT INTO ttrss_users |
0d421af8 | 38 | (login,access_level,last_login,created,pwd_hash,salt) |
c9d5c260 AD |
39 | VALUES (?, 0, null, NOW(), ?,?)"); |
40 | $sth->execute([$login, $pwd_hash, $salt]); | |
0d421af8 AD |
41 | |
42 | return $this->find_user_by_login($login); | |
43 | ||
44 | } else { | |
45 | return $user_id; | |
46 | } | |
47 | } | |
48 | ||
501ed09a | 49 | return $this->find_user_by_login($login); |
0d421af8 AD |
50 | } |
51 | ||
52 | function find_user_by_login($login) { | |
c9d5c260 AD |
53 | $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
54 | login = ?"); | |
55 | $sth->execute([$login]); | |
0d421af8 | 56 | |
c9d5c260 AD |
57 | if ($row = $sth->fetch()) { |
58 | return $row["id"]; | |
0d421af8 AD |
59 | } else { |
60 | return false; | |
61 | } | |
62 | ||
63 | } | |
64 | } |