202 lines
6.7 KiB
PHP
202 lines
6.7 KiB
PHP
|
|
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Reset Password</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
|
|
<!-- Fonts -->
|
|
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700&display=swap" rel="stylesheet">
|
|
|
|
<!-- Font Awesome -->
|
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
|
|
|
<!-- Custom CSS -->
|
|
<link rel="stylesheet" href="css/style.css">
|
|
|
|
<!-- SweetAlert2 -->
|
|
<script src="../dist/sweetalert2.all.min.js"></script>
|
|
|
|
<!-- Custom CSS -->
|
|
<style>
|
|
.btn-primary {
|
|
background-color: #FFA836 !important;
|
|
border-color: #E6732A !important;
|
|
color: white !important;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background-color: #E6732A !important;
|
|
border-color: #C15A1A !important;
|
|
}
|
|
.text-center a {
|
|
color: #E6732A;
|
|
}
|
|
.text-center a:hover {
|
|
color: #C15A1A;
|
|
}
|
|
.icon {
|
|
background: #E6732A;
|
|
color: white;
|
|
padding: 15px;
|
|
border-radius: 50%;
|
|
font-size: 24px;
|
|
width: 50px;
|
|
height: 50px;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
margin: auto;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<section class="ftco-section">
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6 text-center mb-5">
|
|
<h2 class="heading-section">Reset Password</h2>
|
|
</div>
|
|
</div>
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6 col-lg-5">
|
|
<div class="login-wrap p-4 p-md-5">
|
|
<div class="icon d-flex align-items-center justify-content-center">
|
|
<span class="fa fa-lock"></span>
|
|
</div>
|
|
<h3 class="text-center mb-4">Masukkan Password Baru Anda</h3>
|
|
|
|
<!-- Form Reset Password -->
|
|
<form action="" method="POST" class="login-form">
|
|
<div class="form-group">
|
|
<input type="password" name="new_password" class="form-control rounded-left" placeholder="Password Baru" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="password" name="confirm_password" class="form-control rounded-left" placeholder="Konfirmasi Password" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<button type="submit" class="btn btn-primary rounded submit p-3 px-5" name="submit">Perbarui Password</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- Scripts -->
|
|
<script src="js/jquery.min.js"></script>
|
|
<script src="js/popper.js"></script>
|
|
<script src="js/bootstrap.min.js"></script>
|
|
<script src="js/main.js"></script>
|
|
</body>
|
|
</html>
|
|
|
|
<?php
|
|
session_start();
|
|
include '../config.php'; // Path ke file koneksi database Anda
|
|
|
|
// Periksa koneksi database
|
|
if (!$conn) {
|
|
die("Koneksi ke database gagal: " . mysqli_connect_error());
|
|
}
|
|
|
|
// Ambil token dari URL
|
|
$token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING);
|
|
|
|
if ($token) {
|
|
// Escape token untuk keamanan
|
|
$token = mysqli_real_escape_string($conn, $token);
|
|
|
|
// Validasi token dan waktu kadaluwarsa
|
|
$query = "SELECT * FROM admin WHERE reset_token = '$token' AND token_expiry > NOW()";
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
if (mysqli_num_rows($result) > 0) {
|
|
// Token valid
|
|
if (isset($_POST['submit'])) {
|
|
// Ambil password baru dari form
|
|
$new_password = mysqli_real_escape_string($conn, $_POST['new_password']);
|
|
$confirm_password = mysqli_real_escape_string($conn, $_POST['confirm_password']);
|
|
|
|
// Validasi password
|
|
if (strlen($new_password) < 8) {
|
|
echo "<script>
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Password Terlalu Pendek',
|
|
text: 'Password minimal 8 karakter.',
|
|
});
|
|
</script>";
|
|
exit();
|
|
}
|
|
|
|
if ($new_password === $confirm_password) {
|
|
// Hash password baru
|
|
$hashed_password = password_hash($new_password, PASSWORD_ARGON2I);
|
|
|
|
// Update password di database
|
|
$update_query = "UPDATE admin
|
|
SET password = '$hashed_password',
|
|
reset_token = NULL,
|
|
token_expiry = NULL
|
|
WHERE reset_token = '$token'";
|
|
if (mysqli_query($conn, $update_query)) {
|
|
echo "<script>
|
|
Swal.fire({
|
|
title: 'Berhasil!',
|
|
text: 'Password Anda berhasil diperbarui.',
|
|
icon: 'success'
|
|
}).then(() => {
|
|
window.location = 'index.php';
|
|
});
|
|
</script>";
|
|
} else {
|
|
echo "<script>
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Oops...',
|
|
text: 'Terjadi kesalahan saat memperbarui password. Coba lagi nanti.',
|
|
});
|
|
</script>";
|
|
}
|
|
} else {
|
|
echo "<script>
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Password Tidak Cocok',
|
|
text: 'Konfirmasi password harus sama dengan password baru.',
|
|
});
|
|
</script>";
|
|
}
|
|
}
|
|
} else {
|
|
// Token tidak valid atau kedaluwarsa
|
|
echo "<script>
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Link Tidak Valid',
|
|
text: 'Token telah kedaluwarsa atau tidak valid.',
|
|
}).then(() => {
|
|
window.location = 'forgot_password.php';
|
|
});
|
|
</script>";
|
|
exit();
|
|
}
|
|
} else {
|
|
// Token tidak tersedia
|
|
echo "<script>
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Akses Ditolak',
|
|
text: 'Token tidak ditemukan.',
|
|
}).then(() => {
|
|
window.location = 'forgot_password.php';
|
|
});
|
|
</script>";
|
|
exit();
|
|
}
|
|
?>
|