Guest User

Untitled

a guest
May 27th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <html>
  2. <body>
  3.  <?php error_reporting(-1); ini_set('display_errors', 'on'); ?>
  4. <?php
  5. session_start();
  6.            
  7. //Declare username and password variable from login form
  8. $username = $_POST['username'];
  9. $password = $_POST['password'];
  10.  
  11. //Define mySQL server login information
  12. $dbhost = 'localhost';
  13. $dbname = 'basiclogin';
  14. $dbuser = 'root';
  15. $dbpass = 'Password@1'; //not really
  16.  
  17. //Connection variable
  18. $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  19.  
  20. //Begin using database
  21. mysql_select_db($dbname, $conn);
  22.  
  23. //SQL injection protection
  24. $username = mysql_real_escape_string($username);
  25.  
  26. //Define the query to be used by mySQL
  27. $query = "SELECT password, salt
  28.        FROM users
  29.        WHERE username = '$username';";
  30.  
  31. //Die if connection is bad
  32. if (!mysql_query($query,$conn))
  33.   {
  34.   die('Error: ' . mysql_error());
  35.   }
  36.  
  37.  
  38. //Set $result equal to the username
  39. $result = mysql_query($query);
  40. if(mysql_num_rows($result) < 1) //no such user exists
  41. {
  42.     //Return the user to the login page
  43.     header('Location: login.php');
  44. }
  45.  
  46.  
  47. $userData = mysql_fetch_array($result, MYSQL_ASSOC);
  48. $hash = hash('sha256', $userData['salt'] . hash('sha256', $password) );
  49.  
  50. if($hash != $userData['password']) //incorrect password
  51. {
  52.     //Return the user to the login page
  53.     header('Location: login.php');
  54.  
  55. }
  56.  
  57. else
  58. {
  59. //Login Successful
  60.            
  61.                      
  62.             $_SESSION['authlevel'] = $userData['authlevel'];
  63.             $_SESSION['is_logged_in'] = true;
  64.             $_SESSION['member_name'] = $userData['username'];
  65.             header("location: welcome.php");
  66.                
  67.            
  68. }
  69. ?>
  70.  
  71.  
  72. </body>
  73. </html>
Add Comment
Please, Sign In to add comment