Advertisement
gitlez

YA: Simple Username/Password From File

Sep 7th, 2011
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. <?php
  2. // http://answers.yahoo.com/question/index?qid=20110906181257AAl7Fre
  3. $user = strtolower( $_POST['user'] );
  4. $pass = $_POST['pass'];
  5.  
  6. $lines = file('/assets/people.txt');
  7. foreach($lines as $line){
  8.     $parts = explode(':',$line);
  9.     if($parts[0] == $user && $parts[1] == $pass){
  10.         // Username & Password Combination is all good.
  11.         echo 'That is a Good Username and Password Combo';
  12.     }else{
  13.         // Invalid Username/Password Combination
  14.         echo 'Invalid Username/Password Combo';
  15.     }
  16. }
  17.  
  18. // This will work fine for a small number of entries, but for a larger list of people, this
  19. // approach would be very taxing on your system.
  20.  
  21. /*             ALTERNATIVE APPROACH
  22.  
  23.  
  24. $user = strtolower( $_POST['user'] );
  25. $pass = $_POST['pass'];
  26. $combo = $user . ':' . $pass . PHP_EOL;
  27. $list = file_get_contents( '/assets/people.txt');
  28. if(strpos($list,$combo) !== false){
  29.     // Username & Password Combination is all good.
  30.     echo 'That is a Good Username and Password Combo';
  31. }else{
  32.     // Invalid Username/Password Combination
  33.     echo 'Invalid Username/Password Combo';
  34. }
  35.  
  36.  
  37. */
  38.  
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement