-
Notifications
You must be signed in to change notification settings - Fork 1
/
ganti-password.php
168 lines (148 loc) · 6.03 KB
/
ganti-password.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
// panggil koneksi db
require "db.php";
// panggil file functions.php
require "functions.php";
// aktifkan session
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ganti Password</title>
<?php require "headtags.php" ?>
</head>
<body>
<!-- navbar -->
<?php require "navbar.php" ?>
<!-- form -->
<div class="container my-5">
<div class="row">
<div class="col-xl-6 offset-xl-3">
<div class="card">
<div class="card-header text-center">
<h3>Ganti Kata Sandi</h3>
</div>
<div class="card-body">
<form action="" method="POST">
<div class="form-group">
<label for="exampleInputEmail1">Kata Sand Lama</label>
<input type="password" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Kata Sandi Lama" name="passwordLama">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Kata Sandi Baru</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Kata Sandi Baru" name="password1">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Ulangi Kata Sandi Baru</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Ulangi Kata Sandi Baru" name="password2">
</div>
<button type="submit" name="simpanData" class="btn btn-primary btn-block">Ganti Kata Sandi</button>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- end form -->
<!-- footer -->
<?php include 'footer.php' ?>
</body>
</html>
<?php
cekBelumLogin();
// jika tombol ganti kata sandi di tekan
if (isset($_POST["simpanData"])) {
// ambil data form
$passwordLama = $_POST["passwordLama"];
$password1 = $_POST["password1"];
$password2 = $_POST["password2"];
// validasi
validasiPassword($password1);
validasiPassword($password2);
// cek jika password baru tidak sama
if ($password1 != $password2){
echo "
<script>
Swal.fire('PERUBAHAN GAGAL','Password Baru Tidak Sama','error');
</script>
";
}else{ // jika password baru sama
// jika role user = admin
if (isset($_SESSION["admin"])){
// ambil data admin
$admin = mysqli_query($db, "SELECT * FROM admin");
$admin = mysqli_fetch_assoc($admin);
// cek password lama
// jika tidak sama
if (password_verify($passwordLama, $admin["password"])){
$password = password_hash($password1, PASSWORD_DEFAULT);
mysqli_query($db, "UPDATE admin SET password = '$password'");
echo "
<script>
Swal.fire('PERUBAHAN BERHASIL','Password Berhasil Diganti','success').then(function(){
window.location = 'ganti-password.php';
});
</script>
";
}else {
echo "
<script>
Swal.fire('PERUBAHAN GAGAL','Password Lama Salah','error');
</script>
";
}
}else if (isset($_SESSION["perusahaan"])){ // jika role user = perusahaan
// ambil data perusahaan
$email = $_SESSION["perusahaan"];
$perusahaan = mysqli_query($db, "SELECT * FROM perusahaan WHERE email = '$email'");
$perusahaan = mysqli_fetch_assoc($perusahaan);
// cek password lama
// jika tidak sama
if (password_verify($passwordLama, $perusahaan["password"])){
$password = password_hash($password1, PASSWORD_DEFAULT);
mysqli_query($db, "UPDATE perusahaan SET password = '$password' WHERE email = '$email'");
echo "
<script>
Swal.fire('PERUBAHAN BERHASIL','Password Berhasil Diganti','success').then(function(){
window.location = 'ganti-password.php';
});
</script>
";
}else {
echo "
<script>
Swal.fire('PERUBAHAN GAGAL','Password Lama Salah','error');
</script>
";
}
}else if (isset($_SESSION["pelamar"])){ // jika role user = pelamar
// ambil data pelamar
$email = $_SESSION["pelamar"];
$pelamar = mysqli_query($db, "SELECT * FROM pelamar WHERE email = '$email'");
$pelamar = mysqli_fetch_assoc($pelamar);
// cek password lama
// jika tidak sama
if (password_verify($passwordLama, $pelamar["password"])){
$password = password_hash($password1, PASSWORD_DEFAULT);
mysqli_query($db, "UPDATE pelamar SET password = '$password' WHERE email = '$email'");
echo "
<script>
Swal.fire('PERUBAHAN BERHASIL','Password Berhasil Diganti','success').then(function(){
window.location = 'ganti-password.php';
});
</script>
";
}else {
echo "
<script>
Swal.fire('PERUBAHAN GAGAL','Password Lama Salah','error');
</script>
";
}
}
}
}
?>