-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth.php
More file actions
54 lines (51 loc) · 1.77 KB
/
auth.php
File metadata and controls
54 lines (51 loc) · 1.77 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
<?php include_once('includes/load.php'); ?>
<?php
$req_fields = array('username','password' );
validate_fields($req_fields);
$username = remove_junk($_POST['username']);
$password = remove_junk($_POST['password']);
if(empty($errors)){
// Add the authenticate function if it's missing
if(!function_exists('authenticate')) {
function authenticate($username='', $password='') {
global $db;
$username = $db->escape($username);
$password = $db->escape($password);
$sql = sprintf("SELECT id,username,password,user_level FROM users WHERE username ='%s' LIMIT 1", $username);
$result = $db->query($sql);
if($db->num_rows($result)){
$user = $db->fetch_assoc($result);
$password_request = sha1($password);
if($password_request === $user['password'] ){
return $user;
}
}
return false;
}
}
$user = authenticate($username, $password);
if($user){
//create session with id
$session->login($user['id']);
//Update Sign in time
updateLastLogIn($user['id']);
// redirect user to group home page by user level
if($user['user_level'] === '1'){
$session->msg("s", "Hello ".$user['username'].", Welcome to Inventory Management System.");
redirect('admin.php',false);
} elseif ($user['user_level'] === '2') {
$session->msg("s", "Hello ".$user['username'].", Welcome to Inventory Management System.");
redirect('special.php',false);
} else {
$session->msg("s", "Hello ".$user['username'].", Welcome to Inventory Management System.");
redirect('home.php',false);
}
} else {
$session->msg("d", "Sorry Username/Password incorrect.");
redirect('index.php',false);
}
} else {
$session->msg("d", $errors);
redirect('index.php',false);
}
?>