Advertisement
Guest User

Untitled

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