forked from khrisnairham/pesona-lokal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cek_kodeverify.php
49 lines (44 loc) · 1.68 KB
/
cek_kodeverify.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
<?php
// Koneksi ke database
// Koneksi ke database
$host = "localhost";
$username = "id20751189_pesonalokal2023";
$database = "id20751189_pesonalokal";
$password = "Pesonalokal2023.";
$conn = new mysqli($host, $username, $password, $database);
if ($conn->connect_error) {
die('Koneksi gagal: ' . $conn->connect_error);
}
// Ambil data dari form ganti password
$verificationCode = $_POST['verification_code'];
$newPassword = $_POST['password'];
$confirmPassword = $_POST['confirm_password'];
// Cek apakah kode verifikasi cocok dengan yang ada di database
$sql = "SELECT * FROM Users WHERE verification_code = '$verificationCode'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Kode verifikasi cocok, dapatkan data pengguna
$row = $result->fetch_assoc();
$userId = $row['id'];
// Validasi konfirmasi password
if ($newPassword === $confirmPassword) {
// Validasi password sesuai kriteria
if (preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{6,}$/', $newPassword)) {
// Update password pengguna
$sql = "UPDATE Users SET password = '$newPassword', verification_code = NULL WHERE id = '$userId'";
if ($conn->query($sql) === TRUE) {
echo "Password berhasil diubah.";
} else {
die('Error: " . $sql . "<br>" . $conn->error');
}
} else {
die('Password harus mengandung minimal satu huruf besar, satu huruf kecil, satu angka, dan memiliki panjang minimal 6 karakter.');
}
} else {
die('Konfirmasi password tidak cocok. Silakan cek kembali.');
}
} else {
die('Kode verifikasi tidak valid. Silakan cek kembali.');
}
$conn->close();
?>