Advertisement
Guest User

Untitled

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