Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // fungsi ganti password
- public function gantipassword($tabel, $password_lama, $password_baru, $where){
- try{
- $query = $this->db->prepare("SELECT * FROM $tabel WHERE password = :password_lama OR username = :username");
- $query->execute(array(":password_lama" => $password_lama, ":username" => $where));
- $data = $query->fetch();
- if ($data) { // jika ada data di database, maka :
- if (password_verify($password_lama, $data['password'])) { // jika password yang di hash cocok, maka :
- $hashpass = password_hash($password_baru, PASSWORD_DEFAULT); // hash password yang diganti
- // edit password lama menjadi password baru berdasarkan user
- $update = $this->db->prepare("UPDATE $tabel SET password = :password_baru WHERE username = :username");
- $update->execute(array(":password_baru" => $hashpass, ":username" => $where));
- echo '<div class="alert alert-success" role="alert">Password berhasil di ubah. </div>';
- }else{
- echo '<div class="alert alert-danger" role="alert">Password lama tidak cocok. Coba lagi</div>';
- }
- }
- }catch(PDOexception $e){
- echo $e->getMessage();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement