Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4. require_once('sqlfunction.php');
  5.  
  6. $message = $userID = $result = "";
  7.  
  8. if(isset($_SESSION['userID'])) {
  9. $message = "User is already logged in";
  10. } else if(strlen($_POST['username']) > 20 || strlen($_POST['username']) < 4) {
  11. $message = "Incorrect length for username";
  12. } else if($_POST['password'] > 20 || strlen($_POST['password']) < 4) {
  13. $message = "Incorrect length for password";
  14. } else if(ctype_alnum($_POST['username']) != true) {
  15. $message = "Username must be alpha-numeric";
  16. } else if(ctype_alnum($_POST['password']) != true) {
  17. $message = "Password must be alpha-numeric";
  18. } else {
  19.  
  20. $username = filter_var($_POST['username'],FILTER_SANITIZE_STRING);
  21. $password = filter_var($_POST['password'],FILTER_SANITIZE_STRING);
  22. $password = password_hash($password, PASSWORD_DEFAULT);
  23.  
  24. try {
  25. $link = f_sqlConnect();
  26. $sql = "select userID from userDfn where username='".$username."' and password='".$password."';";
  27. if($result = mysqli_query($link,$sql)) {
  28. while($row = mysqli_fetch_assoc($result)) {
  29. $userID = $row['userID'];
  30. $_SESSION['userID'] = $userID;
  31. $_SESSION['timeout'] = time();
  32. header("Location: ToDoApp.php");
  33. $message = "You're now logged in";
  34. }
  35. }
  36. if($userID == false) {
  37. $message = "Login failed";
  38. }
  39. } catch (Exception $e) { $message = "Unable to process request"; }
  40. }
  41.  
  42. ?>
  43. <!DOCTYPE html>
  44. <html lang="en">
  45. <head>
  46. <meta charset="utf-8">
  47. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  48. <meta name="viewport" content="width=device-width, initial-scale=1">
  49.  
  50. <title>Login Submit</title>
  51.  
  52.  
  53. </head>
  54. <body>
  55. <p><?php echo $message; ?></p>
  56.  
  57.  
  58.  
  59. </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement