0

Hi i want to know if someone can help me to integrate the recaptcha to a existing login form.

This is my form code:

    <body>
  <div id="page-loader"></div>
        <!-- Login Content -->
        <div class="content overflow-hidden">
            <div class="row">
                <div class="col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3 col-lg-4 col-lg-offset-4">
                    <!-- Login Block -->
                    <div class="block block-themed animated fadeIn">
                        <div class="block-header bg-primary">
                            <ul class="block-options">
                                <!-- Soon
                                <li>
                                    <a href="#">Forgot Password?</a>
                                </li>-->
                                <li>
                                    <a href="<?php echo $boardurl; ?>register.php" data-toggle="tooltip" data-placement="left" title="New Account"><i class="si si-plus"></i></a>
                                </li>
                            </ul>
                            <h3 class="block-title">Login</h3>
                        </div>
                        <div class="block-content block-content-full block-content-narrow">
                            <!-- Login Title -->
                            <h1 class="h2 font-w600 push-30-t push-5"><?php echo $website; ?></h1>
                            <p>Welcome, please login.</p>
                            <!-- END Login Title -->

                            <!-- Login Form -->


                            <form class="js-validation-login form-horizontal push-30-t push-50" action="<?php echo $boardurl; ?>login.php" method="POST">
                                <div class="form-group">
                                    <div class="col-xs-12">
                                        <div class="form-material form-material-primary floating">
                                            <input class="form-control" type="text" id="login-username" name="username">
                                            <label for="login-username">Username</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-xs-12">
                                        <div class="form-material form-material-primary floating">
                                            <input class="form-control" type="password" id="login-password" name="password">
                                            <label for="login-password">Password</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-xs-12 col-sm-6 col-md-4">
                                        <div class="g-recaptcha" data-sitekey="<?php echo $publickey; ?>"></div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-xs-12">
                                        <label class="css-input switch switch-sm switch-primary">
                                            <input type="checkbox" id="login-remember-me" name="login-remember-me"><span></span> Remember Me?
                                        </label>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-xs-12 col-sm-6 col-md-4">
                                        <button class="btn btn-block btn-primary" type="submit"><i class="si si-login pull-right"></i> Log in</button>
                                    </div>
                                </div>
                            </form>
                            <!-- END Login Form -->
                        </div>
                    </div>
                    <!-- END Login Block -->
                </div>
            </div>
        </div>
        <!-- END Login Content -->

In the footer I added this

<script src='https://www.google.com/recaptcha/api.js'></script>

And in the form already added

<div class="g-recaptcha" data-sitekey="<?php echo $publickey; ?>">

The plubic key is store in the db via setting field.

Now i need to integrate the post side with my post code

This is my post code:

    if(isset($_POST['username']) && isset($_POST['password'])){

    $username = mysqli_real_escape_string($con, $_POST['username']);
    $password = mysqli_real_escape_string($con, md5($_POST['password']));

    $result = mysqli_query($con, "SELECT * FROM `users` WHERE `username` = '$username'") or die(mysqli_error($con));
    if(mysqli_num_rows($result) < 1){
        header("Location: login.php?error=incorrect-password");
    }
    while($row = mysqli_fetch_array($result)){
        if($password != $row['password']){
            header("Location: login.php?error=incorrect-password");
        }elseif($row['status'] == "0"){
            header("Location: login.php?error=banned");
        }else{
            $_SESSION['id'] = $row['id'];
            $_SESSION['username'] = $username;
            $_SESSION['email'] = $row['email'];
            $_SESSION['rank'] = $row['rank'];
            $_SESSION['active'] = $_SESSION['active'];
            header("Location: index.php");
        }
    }

}

I really appreciate the help you can give me.

Juan Montes
  • 33
  • 1
  • 7
  • https://stackoverflow.com/questions/27706594/how-can-i-make-recaptcha-a-required-field?rq=1 – TSR May 23 '17 at 06:16

1 Answers1

0

Will you be able to use this composer? https://github.com/google/recaptcha

If so it can simplify your life quite a lot, you have an example there of how to verify the user response.

Let me know if you can't I will try to help with a more detailed explanation.

vic0707
  • 71
  • 1
  • 2
  • 8
  • Hello, I have seen and tried but I did not understand anything xD I only have basic knowledge in php could you help me to integrate it with my code? I have the library already on my server in this way recaptcha / src / autoload.php – Juan Montes May 23 '17 at 21:30