Guest User

Untitled

a guest
May 28th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <html>
  2. <body>
  3.  <?php error_reporting(-1); ini_set('display_errors', 'on'); ?>
  4.  
  5. <?php
  6. session_start();
  7.            
  8. //Declare username and password variable from login form
  9. $username = $_POST['username'];
  10. $password = $_POST['password'];
  11.  
  12. //Connect to MySQL server
  13. $conn = new PDO('mysql:host=localhost;dbname=basiclogin', 'root', 'Password@1');
  14.  
  15. try {
  16. $stmt = $conn->prepare("SELECT * FROM users WHERE username=?");
  17. $stmt->execute(array($username));
  18. $row_count = $stmt->rowCount();
  19. $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
  20. }
  21.  
  22. catch (PDOException $ex)
  23. {
  24. echo "Error.";
  25. //Write error to log
  26. }
  27.  
  28. //Number of rows < 1 than user not found
  29. if($row_count < 1)
  30. {
  31. header('Location: index.php');
  32. }
  33.  
  34. //TO BE REPLACED WITH CRYPT() FUNCTIONALITY
  35. $hash = hash('sha256', $results['0']['salt'] . hash('sha256', $password) );
  36.  
  37. if($hash != $results['0']['password']) //incorrect password
  38. {
  39.     //Return the user to the login page
  40.     header('Location: login.php');
  41.  
  42. }
  43.  
  44. else
  45. {
  46. //Login Successful
  47.                    
  48.             $_SESSION['authlevel'] = $results[0]['authlevel'];
  49.             $_SESSION['is_logged_in'] = true;
  50.             $_SESSION['member_name'] = $results[0]['username'];
  51.             header("location: welcome.php");       
  52. }
  53.  
  54. ?>
  55. </body>
  56. </html>
Add Comment
Please, Sign In to add comment