-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.php
More file actions
64 lines (54 loc) · 1.69 KB
/
auth.php
File metadata and controls
64 lines (54 loc) · 1.69 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* @author Konstantin Zangerle
* @license BSD 2-Clause
*
* Authentification script of APVEL
*
* Authentificates the user and sets SESSION variables
* (user,groups).
* Uses parts of DokuWikis src to do this.
*/
require_once 'DokuWiki/PassHash.class.php';
require 'smarty3/Smarty.class.php';
require 'lib.php';
$smarty = new Smarty();
$smarty->setTemplateDir('smarty/templates');
$smarty->setCompileDir('smarty/templates_c');
$smarty->setCacheDir('smarty/cache');
$smarty->setConfigDir('smarty/configs');
session_start();
if (isset($_GET['logout'])) {
session_unset();
}
if (isset($_SESSION['user'])) {
$smarty->assign('loggedIn', true);
} else if (isset($_POST['user']) and isset($_POST['password'])) {
$handle = fopen("DokuWiki/users.auth.php", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
if(startsWith($line, $_POST['user'])) {
// do the auth
$lineExplode = explode(":", $line);
if($lineExplode[0] != $_POST['user']) {
continue;
}
$cHash = new PassHash();
if ($cHash->verify_hash($_POST['password'], $lineExplode[1])) {
$_SESSION['user'] = $_POST['user'];
$_SESSION['groups'] = array_map('trim', explode(",", $lineExplode[4]));
$smarty->assign('loggedIn', true);
header("Location: index.php");
exit();
} else {
error_log("Login attempt with wrong credentials for user: " . $_POST['user']);
}
}
}
fclose($handle);
} else {
// error opening the file.
}
}
$smarty->display('auth.tpl');
?>