-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_password.php
48 lines (39 loc) · 1.59 KB
/
update_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
<?php
// request method harus POST
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
die("<h1>404 PAGE NOT FOUND</h1>");
}
session_start();
// die(print_r($_SESSION['current_peminjam']));
// cek login
if (!isset($_SESSION['logged_in']) || !$_SESSION['logged_in']) {
header('Location: ../orca/ganti_password.php');
die;
}
require_once('Connections/koneksi.php');
$user = mysqli_fetch_array($koneksi->query("SELECT * FROM `peminjam` WHERE `no_induk`= '".$_SESSION['current_id']."'"));
// die(print_r($user));
$passwordlama = $_POST['pass_lama'];
$passwordbaru = $_POST['pass_baru'];
$konfirmasi = $_POST['konfirmasi'];
if ($passwordlama != $user['kata_sandi']) {
$_SESSION['errors'] = 'Password lama yang dimasukkan salah';
echo '<script> window.history.go(-1) </script>';
die($_SESSION['errors']);
} elseif ($konfirmasi != $passwordbaru) {
$_SESSION['errors'] = 'Password yang dimasukkan tidak sesuai';
echo '<script> window.history.go(-1) </script>';
die($_SESSION['errors']);
} elseif ($passwordbaru == $passwordlama) {
$_SESSION['errors'] = 'Passowrd yang dimasukkan adalah password lama';
header('Location: ../orca/ganti_password.php');
die($_SESSION['errors']);
}
if(empty(trim($passwordbaru))) {
$_SESSION['errors'] = 'Password yang dimasukkan tidak mengandung karakter atau kosong';
echo '<script> window.history.go(-1) </script>';
die($_SESSION['errors']);
}
$updatepassword= $koneksi->query("UPDATE `peminjam` SET `kata_sandi` = '$passwordbaru' WHERE `no_induk`= '".$_SESSION['current_id']."'");
$_SESSION['success'] = 'Password telah diganti';
echo '<script> window.history.go(-1) </script>';