-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathganpas.php
More file actions
34 lines (27 loc) · 939 Bytes
/
ganpas.php
File metadata and controls
34 lines (27 loc) · 939 Bytes
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
<?php
// koneksi database
$id = $_SESSION['id'] ?? null;
if (!$id) {
die("Anda belum login.");
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$passwordBaru = $_POST['katasandi'];
if (!empty($passwordBaru)) {
// hash password agar lebih aman
$passwordHash = password_hash($passwordBaru, PASSWORD_DEFAULT);
$stmt = $koneksi->prepare("UPDATE users SET katasandi=? WHERE id=?");
$stmt->bind_param("si", $passwordHash, $id);
$stmt->execute();
echo "<script>alert('Password berhasil diganti!'); window.location='dashboard_admin.php';</script>";
exit;
} else {
echo "<script>alert('Password baru tidak boleh kosong!');</script>";
}
}
?>
<h2><center>GANTI PASSWORD</center></h2>
<form method="POST">
<label>Password Baru</label><br>
<input type="password" name="katasandi" required><br><br>
<button type="submit">Ganti Password</button>
</form>