2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/content/time_tracker/open_source/credits.htm
27 // +----------------------------------------------------------------------+
30 * Auth_db class is used to authenticate users against internal DB
31 * @package TimeTracker
33 class Auth_db extends Auth {
36 * Authenticate user against internal users DB
38 * @param string $login
39 * @param string $password
42 function authenticate($login, $password)
44 $mdb2 = getConnection();
46 // Try md5 password match first.
47 $sql = "SELECT id FROM tt_users
48 WHERE login = ".$mdb2->quote($login)." AND password = md5(".$mdb2->quote($password).") AND status = 1";
50 $res = $mdb2->query($sql);
51 if (is_a($res, 'PEAR_Error')) {
52 die($res->getMessage());
55 $val = $res->fetchRow();
57 return array('login'=>$login,'id'=>$val['id']);
60 // If the OLD_PASSWORDS option is defined - set it.
61 if (defined('OLD_PASSWORDS') && isTrue(OLD_PASSWORDS)) {
62 $sql = "SET SESSION old_passwords = 1";
63 $res = $mdb2->query($sql);
64 if (is_a($res, 'PEAR_Error')) {
65 die($res->getMessage());
69 // Try legacy password match. This is needed for compatibility with older versions of TT.
70 $sql = "SELECT id FROM tt_users
71 WHERE login = ".$mdb2->quote($login)." AND password = password(".$mdb2->quote($password).") AND status = 1";
72 $res = $mdb2->query($sql);
73 if (is_a($res, 'PEAR_Error')) {
74 die($res->getMessage());
76 $val = $res->fetchRow();
78 return array('login'=>$login,'id'=>$val['id']);
84 function isPasswordExternal() {