WordPress.org

Support

Support » Themes and Templates » Login Form Honey Pot

Login Form Honey Pot

Viewing 3 replies - 1 through 3 (of 3 total)
  • spudnic072
    Member

    @spudnic072

    *The new field shows fine, and it redirects properly BUT only if an invalid username and password is entered….

    spudnic072
    Member

    @spudnic072

    This does the trick.

    //LOGIN HONEYPOT
    	//Add the new form field
    	//name the input body, better chance of attracting bots
        add_action('login_form','myLogin_honeypot_form');
        function myLogin_honeypot_form (){
            $body = ( isset( $_POST['body'] ) ) ? $_POST['body']: '';
            ?>
            <p id="notThere">
                <label for="body"><?php _e('If you can see the below box, do not input any text. This is a test.','mydomain') ?><br />
                <input type="text" name="body" id="body" class="input" value="<?php echo esc_attr(stripslashes($body)); ?>" size="25" /></label>
            </p>
            <?php
        }
    
    	//add the field processing
    	add_filter('login_errors','myLogin_HoneyPot_Error');
    	function myLogin_HoneyPot_Error(){
    	if( strlen( $_POST['body'] ) > 0 ){
    			//login uses a string for error handling
    			//if login error is set the login for will still process, so we have to sabotage the login variable $username
    			$error = sprintf( __( '<strong>ERROR</strong>: Invalid Login. <a href="%s" title="Password Lost and Found">Lost your password</a>?' ), wp_lostpassword_url() );
    			$username = '';
    			return $error;
    		}
    	}

    spudnic072
    Member

    @spudnic072

    Hide the field with

    notThere{
    display: none;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Login Form Honey Pot’ is closed to new replies.