donnykurnia

Perbaikan COBA

Jan 12th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $koneksi_database = mysqli_connect("localhost", "root", "", "login");
  3.  
  4. if ( isset($_POST['user']) && isset($_POST['password']) ) {
  5.     $user = $_POST['user'];
  6.     $pass = $_POST['password'];
  7.  
  8.     $stmt = mysqli_prepare($koneksi_database, "select * from login_admin where user_name=?");
  9.     mysqli_stmt_bind_param($stmt, 's', $user);
  10.     mysqli_stmt_execute($stmt);
  11.     $result = mysqli_stmt_get_result($stmt);
  12.     if ( $row = mysqli_fetch_array($result, MYSQLI_ASSOC) ) {
  13.         //cek password di database, asumsi sudah pakai password_hash saat menyimpan password
  14.         if ( password_verify($pass, $row['user_pass']) ) {
  15.             session_start();
  16.             $_SESSION['user_id'] = $row['id'];
  17.             header("location:admin.php");
  18.             exit(0); // memastikan kode berhenti di titik ini.
  19.         }
  20.     }
  21.     // jika tidak ada data, atau password tidak cocok, maka akan sampai ke titik ini.
  22.     // best practice: jangan beritahu secara tepat bahwa username yg salah atau password yg salah
  23.     echo "Username dan/atau Password salah!";
  24. }
  25. else {
  26.     echo "User name dan Password tidak boleh kosong";
  27. }
Add Comment
Please, Sign In to add comment