Advertisement
qoqvja-

stmt native

Nov 22nd, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['login'])) {
  3.  
  4. $username = filter_input(INPUT_POST,'username',FILTER_SANITIZE_STRING);
  5. $password = filter_input(INPUT_POST,'password',FILTER_SANITIZE_STRING);
  6.  
  7. if (empty($username) || empty($password)) {
  8. echo "filed tidak boleh kosong";
  9. exit();
  10. }
  11.  
  12. $query = "SELECT * FROM users WHERE username=:username";
  13. $query_params = array(
  14. ":username" => $username
  15. );
  16. try {
  17. $stmt = $db->prepare($query);
  18. $result = $stmt->execute($query_params);
  19. }
  20. catch (PDOException $error) {
  21. die("error value $error->getmessege");
  22. }
  23. $row = $stmt->fetch();
  24.  
  25. $login_ok = false;
  26.  
  27. if ($row) {
  28.  
  29. $checkpassword = hash('sha256', $password . $row['salt']);
  30. for ($round=0; $round < 65536 ; $round++) {
  31. $checkpassword = hash('sha256',$checkpassword . $row['salt']);
  32. }
  33. if ($checkpassword === $row['password']) {
  34. $login_ok = true;
  35. }
  36. }
  37. if ($login_ok) {
  38.  
  39. unset($row['password']);
  40. unset($row['salt']);
  41. $_SESSION['user'] = $row['username'];
  42. header("Location:../home");
  43. }
  44. else{
  45. echo " login gagal ";
  46. die();
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55.  
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement