-
Notifications
You must be signed in to change notification settings - Fork 3
/
login.php
45 lines (38 loc) · 1.46 KB
/
login.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
<?php
include "connection.php";
include "Users.php";
session_start();
$user = new Users();
if (isset($_POST['login'])) {
if (strlen($_POST['nip']) <= 2 || strlen($_POST['password']) <= 2) {
header("Location:index.php?message=Data inputan tidak valid!");
} else {
$user->set_login_data($_POST['nip'], $_POST['password']);
$id = $user->get_employee_id();
$password = $user->get_password();
$sql = "SELECT * FROM users WHERE employee_id = $id";
$result = $db->query($sql);
if ($result->num_rows > 0) {
//Cek password
$row = mysqli_fetch_assoc($result);
if (password_verify($password, $row['password'])) {
//data yang akan masuk ke bagian dashboard
$_SESSION['status'] = "login";
$_SESSION['fullname'] = $row['fullname'];
$_SESSION['employee_id'] = $row['employee_id'];
$_SESSION['role'] = $row['role'];
if ($row['role'] == "admin") {
header("Location:dashboard_admin/index.php");
exit;
} else {
header("Location:dashboard/index.php");
exit;
}
} else {
header("Location:index.php?message=Data tidak ditemukan di database!");
}
} else {
header("Location:index.php?message=Data tidak ditemukan di database!");
}
}
}