forked from OpenEdition/OTX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotx.func.php
29 lines (23 loc) · 889 Bytes
/
otx.func.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
/**
* @package OTX
* @copyright Centre pour L'édition Électronique Ouverte
* @licence http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
**/
/** OTX Authentication **/
function otx_auth() {
if (isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW'])) {
$login = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
$config = OTXConfig::singleton();
$db = new PDO($config->db->dsn, $config->db->user, $config->db->password);
$row = $db->query("SELECT password FROM users WHERE username=" . $db->quote($login))->fetch();
$user_password = $row['password'];
if (crypt($password, $user_password) !== $user_password)
{
header('WWW-Authenticate: Basic realm="OTX Realm"');
header('HTTP/1.0 401 Unauthorized');
die();
}
}
}