I create a login script using a brute force checker that displays reCAPTCHA when it starts. The problem that I encountered is that when the correct username / password / captcha answer is entered, the script input is started, but not until most of the page content has been loaded (this happens after the form is submitted). As a result, I have to press F5 to refresh the page and resubmit the form data so that the session is active when the page starts loading.
Now the problem I am facing is that after submitting the form (when CAPTCHA is required), the session does not start until index.php gets
else { $captchaResponse = 1; $auth = Auth::verifyPass($userName,$password,$captchaResponse); }
I am focused on how I can reorganize this so that the session is started before that. Any ideas?
The first part is the index.php page, which contains code that runs if a brute force attempt is detected. This part of the code starts with a conditional if ($ auth === "bruteForce"). This code displays reCAPTCHA and should present a username, password, and reCAPTCHA response code (0-incorrect answer, 1-correct answer) log back in.
<?php include('includes/header.php'); spl_autoload_register(function ($class){ include 'includes/class.' . $class . '.php'; }); if(null !==(filter_input(INPUT_POST,'userName'))){$userName = filter_input(INPUT_POST,'userName');} if(null !==(filter_input(INPUT_POST,'password'))){$password = filter_input(INPUT_POST,'password');} if(isset($userName)&& isset($password)){ $auth = Auth::verifyPass($userName,$password); } if(isset($_GET['logout']) && $_GET['logout'] == true){ session_start(); session_destroy(); setcookie ("PHPSESSID", "", time() - 3600, "/"); header("Location: index.php"); } if(Auth::checkLoggedIn() === true){ if(session_id() !== ''){echo 'Session ID is not blank<br />';} echo '<a href="index.php?logout=true">Logout</a><br />'; echo 'Welcome! This is protected content!' . "<br />"; } if(!Auth::checkLoggedIn()) : ?> <h1>Sign In</h1> <?php if(isset($userName) && isset($password)){if($auth === "invalidPassword"){echo '<span class="error">Invalid username or password</span>';}} ?> <form name="login" method="post" action="index.php" id="loginForm"> <ul> <li> <input placeholder="Username" type="text" name="userName" id="userName" class="login" /> </li> <li> <input placeholder="Password" type="password" name="password" id="password" class="login" /> </li> <?php if(isset($userName) && isset($password)){ echo $auth . "<br />"; if($auth === "bruteForce"){ echo $auth; require_once('includes/recaptchalib.php'); <div class="clearAll"> </div> <li id="submit"> <input type="submit" value="Login" id="loginBtn" class="login" /> </li> <li id="reset"> <input type="reset" value="Reset" id="resetBtn" class="login" /> </li> </ul> </form> <div class="clearAll"> </div> <h1>New User?</h1> <p><a href="register.php">Sign Up!</a></p> <?php endif; ?> <div class="clearAll"> </div> <?php include('includes/footer.php'); ?> </body> </html>
This is a login feature.
public static function verifyPass($username,$password,$captchaResponse = 3){ $authenticatedUser = FALSE; $bruteTest = self::_bruteTest($username); if($bruteTest === TRUE && $captchaResponse === 3){ $status = "bruteForce"; return $status; } else if($bruteTest === TRUE && $captchaResponse === 0){
php login forms captcha recaptcha
justinc.me
source share