Guest User

Untitled

a guest
Jul 3rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <?php
  2. // Include functions
  3. session_start();
  4.  
  5. error_reporting(E_STRICT);
  6. ini_set("display_errors", "on");
  7.  
  8. //Check for injection and if clean then sanitize the string
  9. $username = $_POST['username'];
  10. if (preg_match('%[*()/\\#=+-]%', $username)) {
  11. $errors[] = "nice try hacker :)";
  12. }
  13. else {
  14. $username = stripslashes($username);
  15. $username = mysql_real_escape_string($username);
  16. }
  17.  
  18. //Check for injection and if clean then sanitize the string
  19. $password = $_POST['password'];
  20. if (preg_match('%[*()/\\#=+-]%', $username)) {
  21. $errors[] = "nice try hacker :)";
  22. }
  23. else {
  24. $password = stripslashes($password);
  25. $password = mysql_real_escape_string($password);
  26. }
  27.  
  28. $errors = array();
  29.  
  30. //connect to database and check for a valid username
  31. $usernameGrab = "SELECT * FROM `users` WHERE `username` = '$username'";
  32. $usernameResult = $db->query($usernameGrab);
  33. $usernameCount = $usernameResult->size();
  34.  
  35. if (!$usernameResult) {
  36. $errors[] = 'Query Failed. Please contact administrator!';
  37. }
  38. else {
  39. if($usernameCount < 1){
  40. $errors[] = "That username doesn't exist";
  41. }
  42. }
  43.  
  44. //connect to database and check for a valid password
  45. $passwordGrab = "SELECT * FROM `users` WHERE `password` = '$password'";
  46. $passwordResult = $db->query($passwordGrab);
  47. $passwordCount = $passwordResult->size();
  48. if (!$passwordResult) {
  49. $errors[] = 'Query failed. Please contact admionistrator';
  50. }
  51. else {
  52. if($passwordCount < 1) {
  53. $errors[] = 'wrong password!';
  54. }
  55. }
  56.  
  57. //If there was errors > define the errors so they can be output
  58. if (!empty($errors)){
  59. $errorOutput = join('',$errors);
  60. define(ERRORS, $errorOutput);
  61. }
  62.  
  63. //If everything went well > Grab Session Data
  64. else {
  65. include('session.php');
  66. }
  67.  
  68. ?>
Add Comment
Please, Sign In to add comment