Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $koneksi_database = mysqli_connect("localhost", "root", "", "login");
- if ( isset($_POST['user']) && isset($_POST['password']) ) {
- $user = $_POST['user'];
- $pass = $_POST['password'];
- $stmt = mysqli_prepare($koneksi_database, "select * from login_admin where user_name=?");
- mysqli_stmt_bind_param($stmt, 's', $user);
- mysqli_stmt_execute($stmt);
- $result = mysqli_stmt_get_result($stmt);
- if ( $row = mysqli_fetch_array($result, MYSQLI_ASSOC) ) {
- //cek password di database, asumsi sudah pakai password_hash saat menyimpan password
- if ( password_verify($pass, $row['user_pass']) ) {
- session_start();
- $_SESSION['user_id'] = $row['id'];
- header("location:admin.php");
- exit(0); // memastikan kode berhenti di titik ini.
- }
- }
- // jika tidak ada data, atau password tidak cocok, maka akan sampai ke titik ini.
- // best practice: jangan beritahu secara tepat bahwa username yg salah atau password yg salah
- echo "Username dan/atau Password salah!";
- }
- else {
- echo "User name dan Password tidak boleh kosong";
- }
Add Comment
Please, Sign In to add comment