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