Advertisement
VanGans

cek-login

Oct 30th, 2018
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. /* PASSWORD MD5 */
  6. $data = array(
  7.     array(
  8.         'u' => 'admin',
  9.         'p' => '21232f297a57a5a743894a0e4a801fc3'
  10.     )
  11. );
  12.  
  13. if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['__login'])){
  14.     $username = isset($_POST['username']) ? $_POST['username'] : null;
  15.     $password = isset($_POST['password']) ? $_POST['password'] : null;
  16.  
  17.     $login = array(
  18.         'u' => $username,
  19.         'p' => md5($password)
  20.     );
  21.  
  22.     if(in_array($login, $data)){
  23.         $_SESSION['__valid'] = TRUE;
  24.         header('Location: '.$_SERVER['PHP_SELF']);
  25.     }
  26.     else{
  27.         echo "<script>alert('Wrong!')</script>";
  28.     }
  29.  
  30. }
  31.  
  32. ?>
  33.  
  34. <?php if(!isset($_SESSION['__valid'])){ ?>
  35.  
  36. <!DOCTYPE html>
  37. <html>
  38. <head>
  39.     <meta charset="utf-8">
  40.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  41.     <title>Login Page</title>
  42.     <style type="text/css" media="screen">
  43.         .mx-auto{
  44.             margin-left: auto;
  45.             margin-right: auto;
  46.             display: block;
  47.         }
  48.     </style>
  49. </head>
  50. <body>
  51.     <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" accept-charset="utf-8">
  52.         <input type="text" name="username" class="mx-auto" class="username" placeholder="Username"><br>
  53.         <input type="password" name="password" class="mx-auto" placeholder="Password"><br>
  54.         <button type="submit" name="__login" value="Checking Login" class="mx-auto">Login</button>
  55.     </form>
  56. </body>
  57. </html>
  58.  
  59. <?php exit();} ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement