Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. <?php
  2. $errors = array();
  3. require("php_db_info.php");
  4.  
  5. // connect to the database
  6. $connection = @mysqli_connect($servername, $username1, $password, $dbname) or die("Error: Couldn't connect to the database.");
  7. mysqli_select_db($connection,$dbname);
  8. if (isset($_POST['login_user'])) {
  9.  
  10. $username20 = isset($_POST['username']) ? $_POST['username'] : null;
  11. $password120 = isset($_POST['password']) ? $_POST['password'] : null;
  12.  
  13. if (empty($username20)) {
  14. array_push($errors, "Username is required");
  15. }
  16. if (empty($password120)) {
  17. array_push($errors, "Password is required");
  18. }
  19. if (count($errors) == 0) {
  20.  
  21. // $query = "SELECT * FROM users WHERE username='$username20' AND password='$password_hash'";
  22. $query = "SELECT userID,password FROM users WHERE username= ? ";
  23.  
  24. $stmt = $connection->prepare($query);
  25. $stmt->bind_param("s", $username);
  26. $stmt->execute();
  27. $stmt->bind_result($userID,$password);
  28. $stmt->store_result();
  29. if ($stmt->num_rows == 1) //check if the row exists
  30. {
  31. if ($stmt->fetch()) //fetching the contents of the row
  32. {
  33. //verify user password
  34. if (password_verify($password120, $password)) {
  35. //password_verify("userenteredPassword",PasswordFromDatabase);
  36.  
  37. $_SESSION['username'] = $username;
  38. $_SESSION['success'] = "You are now logged in";
  39. $hour = time() + 15 * 24 * 60 * 60;
  40. setcookie('c_username', $username20, $hour);
  41. setcookie('c_password', $password, $hour);
  42. header('location: home.php');
  43.  
  44. } else {
  45.  
  46. array_push($errors, "Password and username does not match");
  47. }
  48.  
  49. }
  50.  
  51. } else {
  52.  
  53. array_push($errors, "Invalid user account");
  54. }
  55.  
  56.  
  57.  
  58. } else {
  59. array_push($errors, "Unknown Error!");
  60. }
  61. }
  62.  
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement