Guest User

Untitled

a guest
Dec 25th, 2017
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.43 KB | None | 0 0
  1.     function auth() {
  2.         session_start();
  3.        
  4.        
  5.         // check to see if the user has been banned by ip first ?
  6.         // edd note
  7.         $maxfailedattempt = 6;
  8.                   $iptocheck = $_SERVER['REMOTE_ADDR'];
  9.   $iptocheck = mysql_real_escape_string($iptocheck);
  10.  
  11.   ///HEY EDD YOU NEED TO WORK OUT IF THIS IS DOING THIS FROM THE USER TABLE
  12.   /// AND BOTH THE IPCHECK TABLE IF THE MAX ATTEMPT IS OVER 6 THEN REDIRECT
  13.   /// THE USER AND CALL THEM A CUNT LOL
  14.                if ($fetch = mysql_fetch_array(mysql_query("SELECT `loggedip` FROM `ipcheck` WHERE `loggedip`='$iptocheck'"))) {
  15.  
  16. //Already has some IP address records in the database
  17. //Get the total failed login attempts associated with this IP address
  18.  
  19.     $resultx = mysql_query("SELECT `failedattempts` FROM `ipcheck` WHERE `loggedip`='$iptocheck'");
  20.     $rowx = mysql_fetch_array($resultx);
  21.     $loginattempts_total = $rowx['failedattempts'];
  22.    
  23.     If ($loginattempts_total > $maxfailedattempt) {
  24.         $registered = FALSE;
  25.        header("Location: disable.php");
  26.                     exit();
  27.     }
  28. }
  29.    
  30.         // POST FORM DATA
  31.         if ((isset($_POST["password"])) && (isset($_POST["username"])) && (isset($_SESSION['LAST_ACTIVITY']) == FALSE)) {
  32.  
  33.             function sanitize($data) {
  34.                 $data = trim($data);
  35.                 $data = htmlspecialchars($data);
  36.                 $data = mysql_real_escape_string($data);
  37.                 return $data;
  38.             }
  39.            
  40.             $this->connect();
  41.             $password = sanitize($_POST["password"]);
  42.             $username = sanitize($_POST["username"]);
  43.             if (!($fetch = mysql_fetch_array(mysql_query("SELECT `username` FROM `username` WHERE `username`='$username'")))) {
  44.  
  45.                 $registered = TRUE;
  46.                 $username = mysql_real_escape_string($username); // just to be sure.
  47.                 $result = mysql_query($query);
  48.                 $row = mysql_fetch_array($result);
  49.                 $resusername = $row['username'];
  50.                 $firsttime = $row['firsttime'];
  51.                 $disable = $row['disable'];
  52.                 $correctpassword = $row['password'];
  53.                 $loginattempts_username = $row['loginattempt'];
  54.                 $salt = substr($correctpassword, 0, 64);
  55.                 $correcthash = substr($correctpassword, 64, 64);
  56.                 $userhash = hash("sha256", $salt . $password);
  57.                 $maxfailedattempt = 6;
  58.                 $iptocheck = $_SERVER['REMOTE_ADDR'];
  59.                 $iptocheck = mysql_real_escape_string($iptocheck);
  60.                
  61.                
  62.                
  63.                
  64.                
  65.                 if ($userhash !== $correcthash) {
  66.                
  67.                         $loginattempts_username = $loginattempts_username + 1;
  68.                         $loginattempts_username = intval($loginattempts_username);
  69.                
  70.                         //update login attempt records
  71.                
  72.                         mysql_query("UPDATE `username` SET `loginattempt` = '$loginattempts_username' WHERE `username` = '$username'");
  73.                
  74.                         //Possible brute force attacker is targeting registered usernames
  75.                         //check if has some IP address records
  76.                
  77.                         if (!($fetch = mysql_fetch_array(mysql_query("SELECT `loggedip` FROM `ipcheck` WHERE `loggedip`='$iptocheck'")))) {
  78.                
  79.                             //no records
  80.                             //insert failed attempts
  81.                
  82.                             $loginattempts_total = 1;
  83.                             $loginattempts_total = intval($loginattempts_total);
  84.                             mysql_query("INSERT INTO `ipcheck` (`loggedip`, `failedattempts`) VALUES ('$iptocheck', '$loginattempts_total')");
  85.                         } else {
  86.                
  87.                             //has some records, increment attempts
  88.                
  89.                             $loginattempts_total = $loginattempts_total + 1;
  90.                             mysql_query("UPDATE `ipcheck` SET `failedattempts` = '$loginattempts_total' WHERE `loggedip` = '$iptocheck'");
  91.                         }
  92.                    
  93.                
  94.                    
  95.                 }
  96.                
  97.                 if ($userhash === $correcthash){
  98.                     session_regenerate_id();
  99.                      
  100.                     $loginattempts_username = 0;
  101.                     $loginattempts_total = 0;
  102.                     $loginattempts_username = intval($loginattempts_username);
  103.                     $loginattempts_total = intval($loginattempts_total);
  104.                     mysql_query("UPDATE `username` SET `loginattempt` = '$loginattempts_username' WHERE `username` = '$username'");
  105.                     mysql_query("UPDATE `ipcheck` SET `failedattempts` = '$loginattempts_total' WHERE `loggedip` = '$iptocheck'");
  106.                     mysql_query("UPDATE `username` SET `online` = 1 WHERE `username` = '$username'");
  107.                     $_SESSION['token'] = md5(uniqid(rand(), 1));
  108.                     $token = $_SESSION['token'];
  109.                     mysql_query("INSERT INTO `sess` (`token`, `username`) VALUES ('$token', '$username')");
  110.                     $_SESSION['loggedin'] = "1";
  111.                     $_SESSION['userName'] = $resusername;
  112.                     $_SESSION['LAST_ACTIVITY'] = time();
  113.                     if ($disable == 1) {
  114.                         header("Location: disable.php");
  115.                         exit();
  116.                     }
  117.                     if ($firsttime == 1) {
  118.                         header("Location: firsttime.php");
  119.                         exit();
  120.                     }
  121.                 }
  122.                
  123.                
  124.             }
  125.             else
  126.             {
  127.             // YEAH I KNOW CODE NEEDS TO COME DOWN HERE FOR IP CHECKING ETC
  128.                
  129.                
  130.                 $registered = FALSE;
  131.                 $iptocheck = $_SERVER['REMOTE_ADDR'];
  132.                 $iptocheck = mysql_real_escape_string($iptocheck);
  133.                 if ($registered == FALSE) {
  134.                     if (!($fetch = mysql_fetch_array(mysql_query("SELECT `loggedip` FROM `ipcheck` WHERE `loggedip`='$iptocheck'")))) {
  135.                          
  136.                         //no records
  137.                         //insert failed attempts
  138.                          
  139.                         $loginattempts_total = 1;
  140.                         $loginattempts_total = intval($loginattempts_total);
  141.                         mysql_query("INSERT INTO `ipcheck` (`loggedip`, `failedattempts`) VALUES ('$iptocheck', '$loginattempts_total')");
  142.                     } else {
  143.                          
  144.                         //has some records, increment attempts
  145.                          
  146.                         $loginattempts_total = $loginattempts_total + 1;
  147.                         mysql_query("UPDATE `ipcheck` SET `failedattempts` = '$loginattempts_total' WHERE `loggedip` = '$iptocheck'");
  148.                     }
  149.                 }
  150.             }
  151.  
  152.        
  153.            
  154.         }
  155.  
  156.             if (isset($_SESSION['loggedin'])) {
  157.                 echo "Welcome " . $_SESSION['userName'];
  158.             }
  159.  
  160.             if (!isset($_SESSION['loggedin'])) {
  161.                 ?>
  162.                 <form id="form1" name="form1" method="post" action="<?php htmlentities($_SERVER['PHP_SELF']); ?>">
  163.                     <table align="center" width="375" border="0" cellpadding="0">
  164.                         <label>Username:</label>
  165.                         <input type="text" name="username" id="username" />
  166.                         <label>Password:</label>
  167.                         <input type="password" name="password" id="password" />
  168.                         <input type="Submit" class="input" name="Submit" id="Submit" value="Login" />
  169.                     </table>
  170.                 </form>
  171.                 <?php
  172.             }
  173.        
  174.     }
Add Comment
Please, Sign In to add comment