Advertisement
Guest User

fungsi.php

a guest
Jul 19th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. // fungsi ganti password
  2. public function gantipassword($tabel, $password_lama, $password_baru, $where){
  3. try{
  4. $query = $this->db->prepare("SELECT * FROM $tabel WHERE password = :password_lama OR username = :username");
  5. $query->execute(array(":password_lama" => $password_lama, ":username" => $where));
  6.  
  7. $data = $query->fetch();
  8.  
  9. if ($data) { // jika ada data di database, maka :
  10. if (password_verify($password_lama, $data['password'])) { // jika password yang di hash cocok, maka :
  11.  
  12. $hashpass = password_hash($password_baru, PASSWORD_DEFAULT); // hash password yang diganti
  13.  
  14. // edit password lama menjadi password baru berdasarkan user
  15. $update = $this->db->prepare("UPDATE $tabel SET password = :password_baru WHERE username = :username");
  16. $update->execute(array(":password_baru" => $hashpass, ":username" => $where));
  17.  
  18. echo '<div class="alert alert-success" role="alert">Password berhasil di ubah. </div>';
  19. }else{
  20. echo '<div class="alert alert-danger" role="alert">Password lama tidak cocok. Coba lagi</div>';
  21. }
  22. }
  23.  
  24. }catch(PDOexception $e){
  25. echo $e->getMessage();
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement