rachmadi

login.php

Jan 30th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php
  2.  
  3. require("config.php");
  4.  
  5. if (!empty($_POST)) {
  6.  
  7.     $query = "SELECT * FROM pengguna WHERE username = :png";
  8.    
  9.     $query_params = array(
  10.         ':png' => $_POST['username']
  11.     );
  12.    
  13.     try {
  14.         $stmt   = $db->prepare($query);
  15.         $result = $stmt->execute($query_params);
  16.     }
  17.     catch (PDOException $ex) {
  18.         $response["sukses"] = 0;
  19.         $response["pesan"] = "Database Error. Silahkan coba lagi!";
  20.         die(json_encode($response));
  21.        
  22.     }
  23.     $validated_info = false;
  24.    
  25.     $row = $stmt->fetch();
  26.     if ($row) {
  27.  
  28.         $password = md5($_POST['password']);
  29.         if ($password === $row['password']) {
  30.             $login_ok = true;
  31.         }
  32.     }
  33.    
  34.     // If the user logged in successfully, then we send them to the private members-only page
  35.     // Otherwise, we display a login failed message and show the login form again
  36.     if ($login_ok) {
  37.         $response["sukses"] = 1;
  38.         $response["pesan"] = "Login Berhasil!";
  39.         die(json_encode($response));
  40.     } else {
  41.         $response["sukses"] = 0;
  42.         $response["pesan"] = "Identitas Invalid!";
  43.         die(json_encode($response));
  44.     }
  45. } else {
  46. ?>
  47.         <h1>Login</h1>
  48.         <form action="login.php" method="post">
  49.             Username:<br />
  50.             <input type="text" name="username" placeholder="username" />
  51.             <br /><br />
  52.             Password:<br />
  53.             <input type="password" name="password" placeholder="password"/>
  54.             <br /><br />
  55.             <input type="submit" value="Login" />
  56.         </form>
  57.         <a href="daftar.php">Daftar</a>
  58.     <?php
  59. }
  60.  
  61. ?>
Add Comment
Please, Sign In to add comment