Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. <?php
  2.  
  3. //BEGIN Include Common Data
  4. include_once ("common.php");
  5. //END Include Common Data
  6.  
  7. //sanitize your input, or your ass is getting hacked
  8. $username = mysql_real_escape_string($_POST['username']);
  9. $password = md5($_POST['password']); //assuming you're using md5s
  10.  
  11. function validateAuth($username,$password){
  12.  
  13.     //i made this a function simply because it's cleaner to put the conditionals all here rather than below
  14.     //if you want more detailed return codes, go ahead and put them in ("bad password", "account expired", etc)
  15.     //except don't actually return a string, i'd return an integer and use a lookup table
  16.  
  17.     $query    = mysql_query("SELECT * FROM useraccounts WHERE `username`='$username' AND `password`='$password'");
  18.     if(mysql_num_rows($query)){
  19.         //username/password were correct, let's make sure their account is activated
  20.         $r    = mysql_fetch_assoc($query);
  21.         if($r['Admin'] == '1'){
  22.             return true;
  23.             //admins need no further validation
  24.         }
  25.         if($r['AccountStart'] >= time() && $r['AccountEnd'] <= time()){
  26.             return true;
  27.             //yep, it's active
  28.         }
  29.         return false;
  30.         //not admin and expired/not yet active
  31.     }
  32.     else{
  33.         return false;
  34.         //bad username/password combo
  35.     }  
  36. }
  37.  
  38. if(validateAuth($username,$password)){
  39.     //set cookies and whatever, log them in
  40.     echo "LOL U LOGGED IN :D";
  41. }
  42. else{
  43.     //do error stuff
  44.     echo "LOL U FAIL D:";
  45. }
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement