SHARE
TWEET

Untitled

a guest Jun 15th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $auth = false; //login status
  3.  
  4. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  5. {
  6.     mysql_connect('127.0.0.1', 'root', '');
  7.     mysql_select_db('test');
  8.  
  9.     //get data from db
  10.     $query = 'SELECT password,salt FROM users WHERE username =' . mysql_escape_string($_POST['username']) . ' LIMIT 1';
  11.     $data = mysql_query($query);
  12.     $data = (object) $data[0];
  13.  
  14.     if ($data->password === md5($_POST['password'] . $data->salt))
  15.     {
  16.         $auth = true;
  17.     }
  18. }
  19. ?>
  20.  
  21. <?php if ($auth): ?>
  22.     Login success
  23. <?php else: ?>
  24.         <form method="POST" action="/">
  25.             <label>Username:</label>
  26.             <input type="text" name="username" />
  27.             <label>Password:</label>
  28.             <input type="password" name="password" />
  29.         </form>
  30. <?php endif; ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top