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