-
Notifications
You must be signed in to change notification settings - Fork 0
/
authent.php
65 lines (51 loc) · 1.2 KB
/
authent.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
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
65
<?php
include_once "functions.php";
if (session_status()==PHP_SESSION_NONE)
session_start();
//returns true if could login, false otherwise
//this function will be removed in time.
function canAuth($login_i, $passwd)
{
if (!isset($_SESSION['user']))
{
$login = htmlspecialchars($login_i);
$userList = file(USERS);
foreach ($userList as $elem)
{
$user = explode(':', $elem);
if ($user[0] == $login)
{
if (password_verify($passwd, $user[1]))
{
addLog(logmsg("Has logged in", $login));
$_SESSION['user'] = $login;
$_SESSION['usrlvl'] = $user[2];
return true;
}
}
}
}
else
{
//send an error message?
addLog(logmsg('Tried logging in a second time....', $_SESSION['user']));
return false;
}
return false;
}
//adds a user.
//this function is only used by the admin...
//$password should not be hashed yet
function addUsr($login, $password, $usrlvl)
{
$user = array();
$user[0] = $login;
$user[1] = password_hash($password, PASSWORD_DEFAULT);
$user[2] = $usrlvl;
if (!($file = fopen(USERS, 'a')))
return false;
fprintf($file, "$user[0]:$user[1]:$user[2]" . PHP_EOL);
fclose($file);
}
//addUsr('Leonardo', 'Les Schtroumpfs de Pascal', 2);
?>