Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.52 KB | None | 0 0
  1. <?
  2. ** -=LOGIN.PHP=- **
  3.  
  4. if($form->num_errors > 0){
  5.    echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
  6. }
  7. ?>
  8. <form action="process.php" method="POST">
  9. <table align="center" border="0" cellspacing="0" cellpadding="3">
  10. <tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td></tr>
  11. <tr><td colspan="2" align="right"><? echo $form->error("user"); ?></td></tr>
  12. <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td></tr>
  13. <tr><td colspan="2" align="right"><? echo $form->error("pass"); ?></td></tr>
  14.  
  15. <tr><td colspan="2" align="right">
  16. <input type="hidden" name="remember" checked>
  17. <input type="hidden" name="sublogin" value="1">
  18. <input type="submit" value="Login"></td><td></td></tr>
  19. <tr><td colspan="2" align="center"><font size="2">[ <a href="forgotpass.php">Forgot Password</a> ] - [
  20. <a href="register.php"> Register </a>]</font></td><td></td></tr>
  21. </table>
  22. </form>
  23.  
  24.  
  25. ** -=PROCESS.PHP-= **
  26.  
  27.       if(isset($_POST['sublogin'])){
  28.          $this->procLogin();
  29.       }
  30. ...
  31.    function procLogin(){
  32.       global $session, $form, $database;
  33.       /* Login attempt */
  34.       $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));
  35.       $subuser = stripslashes($_POST['user']);
  36.      
  37.       if($database->usernameBanned($subuser)){
  38.          $retval = $session->logout();
  39.          header("Location: banned.php");
  40.       }
  41.       /* Login Successful */
  42.       elseif($retval){
  43.          header("Location: ".$session->referrer);
  44.       }
  45.       else{
  46.          $_SESSION['value_array'] = $_POST;
  47.          $_SESSION['error_array'] = $form->getErrorArray();
  48.          header("Location: ".$session->referrer);
  49.       }
  50.    }
  51.  
  52. ** -=SESSION.PHP=- **
  53.  
  54.    function login($subuser, $subpass, $subremember){
  55.       global $database, $form;  //The database and form object
  56.       /* Username error checking */
  57.       $field = "user";  //Use field name for username
  58.       if(!$subuser || strlen($subuser = trim($subuser)) == 0){
  59.          $form->setError($field, "* Username not entered");
  60.       }
  61.       else{
  62.          /* Check if username is not alphanumeric */
  63.          if(!eregi("^([0-9a-z])*$", $subuser)){
  64.             $form->setError($field, "* Username not alphanumeric");
  65.          }
  66.       }
  67.  
  68.       /* Password error checking */
  69.       $field = "pass";  //Use field name for password
  70.       if(!$subpass){
  71.          $form->setError($field, "* Password not entered");
  72.       }
  73.  
  74.       /* Return if form errors exist */
  75.       if($form->num_errors > 0){
  76.          return false;
  77.       }
  78.  
  79.       /* Checks that username is in database and password is correct */
  80.       $subuser = stripslashes($subuser);
  81.       $result = $database->confirmUserPass($subuser, md5($subpass));
  82.  
  83.       /* Check error codes */
  84.       if($result == 1){
  85.          $field = "user";
  86.          $form->setError($field, "* Username not found");
  87.       }
  88.       else if($result == 2){
  89.          $field = "pass";
  90.          $form->setError($field, "* Invalid password");
  91.       }
  92.      
  93.       /* Return if form errors exist */
  94.       if($form->num_errors > 0){
  95.          return false;
  96.       }
  97.  
  98.       /* Username and password correct, register session variables */
  99.       $this->userinfo  = $database->getUserInfo($subuser);
  100.       $this->username  = $_SESSION['username'] = $this->userinfo['username'];
  101.       $this->userid    = $_SESSION['userid']   = $this->generateRandID();
  102.       $this->userlevel = $this->userinfo['userlevel'];
  103.      
  104.       /* Insert userid into database and update active users table */
  105.       $database->updateUserField($this->username, "userid", $this->userid);
  106.       $database->addActiveUser($this->username, $this->time);
  107.       $database->removeActiveGuest($_SERVER['REMOTE_ADDR']);
  108.  
  109.       if($subremember){
  110.          setcookie("cookname", $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH);
  111.          setcookie("cookid",   $this->userid,   time()+COOKIE_EXPIRE, COOKIE_PATH);
  112.       }
  113.      
  114.       $q = "SELECT username,timestamp,banduration FROM ".TBL_BANNED_USERS." ORDER BY username";
  115.       $result = $database->query($q);
  116.       $num_rows = mysql_numrows($result);
  117.  
  118.       for($i=0; $i<$num_rows; $i++){
  119.          $uname = mysql_result($result,$i,"username");
  120.          $time   = mysql_result($result,$i,"timestamp");
  121.          $banlength   = mysql_result($result,$i,"banduration");
  122.  
  123.          $q = "DELETE FROM ".TBL_BANNED_USERS." WHERE ".time()." > $banlength";
  124.          $database->query($q);
  125.  
  126.          return true;
  127.       }
  128.    }
  129.  
  130. ** -=DATABASE.PHP=- **
  131.    function confirmUserPass($username, $password){
  132.       /* Add slashes if necessary (for query) */
  133.       if(!get_magic_quotes_gpc()) {
  134.          $username = addslashes($username);
  135.       }
  136.  
  137.       /* Verify that user is in database */
  138.       $q = "SELECT password FROM ".TBL_USERS." WHERE username = '$username'";
  139.       $result = mysql_query($q, $this->connection);
  140.       if(!$result || (mysql_numrows($result) < 1)){
  141.          return 1; //Indicates username failure
  142.       }
  143.  
  144.       /* Retrieve password from result, strip slashes */
  145.       $dbarray = mysql_fetch_array($result);
  146.       $dbarray['password'] = stripslashes($dbarray['password']);
  147.       $password = stripslashes($password);
  148.  
  149.       /* Validate that password is correct */
  150.       if($password == $dbarray['password']){
  151.          return 0; //Success! Username and password confirmed
  152.       }
  153.       else{
  154.          return 2; //Indicates password failure
  155.       }
  156.    }
  157. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement