Advertisement
Guest User

Untitled

a guest
May 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1. <?php
  2.  
  3. //Important variables
  4. $username = $_POST['username'];
  5. $password = $_POST['password'];
  6. $file = "users.txt";
  7. $text = "\n$username\n$password\n";
  8.  
  9.  
  10.  
  11. /////////////////////////////////////////////////////////
  12. //Checks input for blank entrys//////////////////////////
  13.  
  14. function check_for_blank_entries ($check, $text)
  15.     {
  16.     if($check == NULL)
  17.         {
  18.         echo $text;
  19.         return(FALSE);
  20.         }
  21.     else
  22.     {
  23.         return(TRUE);
  24.     }
  25.     }
  26.    
  27. $username_check_blank = check_for_blank_entries($username, 'Username cannot be blank.<br><br>');
  28.  
  29.  
  30.  
  31. $password_check_blank = check_for_blank_entries($password, 'Password cannot be blank.<br><br>');
  32.  
  33.  
  34. /////////////////////////////////////////////////////////
  35. /////////////////////////////////////////////////////////
  36.  
  37.  
  38. /////////////////////////////////////////////////////////
  39. //Checks for only numbers and letters
  40.  
  41. function check_for_correct_values($check, $text)
  42.     {
  43.         if (! eregi("^[a-zA-Z0-9]*$", $check) )
  44.         {
  45.         echo $text;
  46.         return(FALSE);
  47.         }
  48.         else
  49.         {
  50.         return(TRUE);
  51.         }
  52.     }
  53.  
  54. $username_check_value = check_for_correct_values($username, 'Username contains invalid characters.<br><br>');
  55.  
  56. $password_check_value = check_for_correct_values($password, 'Password contains invalid characters.<br><br>');
  57.  
  58.  
  59. //////////////////////////////////////////////////////////
  60. //////////////////////////////////////////////////////////
  61.  
  62.  
  63. /////////////////////////////////////////////////////////
  64. //Check if username and password exists.
  65.  
  66. function check_files($check, $text)
  67.     {
  68.     $scan = file('users.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  69.     if (in_array("$check", $scan))
  70.         {
  71.         echo $text;
  72.         return(FALSE);
  73.         }
  74.         else
  75.         {
  76.         return(TRUE);
  77.         }
  78.     }
  79.  
  80. $username_check = check_files($username, 'Username is already in use.<br><br>');
  81.  
  82. $password_check = check_files($password, 'Password is already in use.<br><br>');
  83.  
  84.  
  85. /////////////////////////////////////////////////////////
  86. /////////////////////////////////////////////////////////
  87.  
  88.  
  89.  
  90.  
  91. /////////////////////////////////////////////////////////
  92. //Add new user to the list.
  93.  
  94.  
  95. if($username_check_blank  &&  $password_check_blank  &&  $username_check  &&  $password_check  &&  $username_check_value  &&  $password_check_value == FALSE)
  96.     {
  97.     file_put_contents($file, $text, FILE_APPEND);
  98.     echo 'You have been registered successfully.<br><br>';
  99.     }
  100. else
  101.     {
  102.         echo 'not going to register';
  103.     }
  104.  
  105.  
  106. /////////////////////////////////////////////////////////
  107. /////////////////////////////////////////////////////////
  108.  
  109.  
  110.  
  111.  
  112. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement