0

I wonder if someone who knows this with security can help me out? I got a custom made login form (template and functions.php) to which I need to add a security question that I can modify directly whenever needed by editing the template.

The security question is supposed to be easy and yet, "hard". I'm thinking like, "What is 180 - 40 + 60?" and then there's a box next to it for answer input.

What I really need is for the login button to stay inactive until the right answer has been given.

Here's the code for the template:

<?php
/**
* Template name: Login
* Author: Custom text here
*
*/
get_header();
// Send the user to his account or any page if already logged in
if ( is_user_logged_in() ) {
wp_redirect( home_url('/') );
}

// Get login error messages
$login_errors = (isset($_GET['user-login']) ) ? $_GET['user-login'] : 0;

if ( $_POST['action'] == 'log-in' ) {

// Submit the user login inputs
$login = wp_login( $_POST['user-name'], $_POST['password'] );
$login = wp_signon( array( 'user_login' => $_POST['user-name'], 'user_password' => $_POST['password'], 'remember' => $_POST['remember-me'] ), false );

// Redirect to account page after successful login
if ( $login->ID ) {
wp_redirect( home_url('/') );
}}
?>

<div id="content" role="main" class = "user-login" >
<!--<h2 class="page-title"><?php the_title(); ?></h2> -->
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

<?php
// output header error messages
if ( $login_errors === "failed" ) {
echo '<div class="input-error-wrapper"><span class="input-error">Custom text here</span></div>';
} elseif ( $login_errors === "empty" ) {
echo '<div class="input-error-wrapper"><span class="input-error">Custom text here</span></div>';
} elseif ( $login_errors === "false" ) {
echo '<div class="input-error-wrapper"><span class="input-error">Cutom text here</span>';
}

?>
<div class="ml-wrapper">
<div class="ml-section">
<form action="<?php the_permalink(); ?>" method="post" class="sign-in">
<p>
<label for="user-name"><?php _e('User ID'); ?></label>
<input type="text" name="user-name" id="user-name" value="<?php echo wp_specialchars( $_POST['user-name'], 1 ); ?>" />
<div class="space"></div>
<label for="password"><?php _e('Password'); ?></label>
<input type="password" name="password" id="password" />
</p>
<p>
<input type="submit" name="submit" value="<?php _e('Login'); ?>" id = "clfl" />
<input type="hidden" name="action" value="log-in" />
</p>
</form>
</div></div>
<?php endwhile; ?>

</div>
<?php
get_footer();

And here's the code that goes into the functions.php file:

function redirect_login_page() {
$login_page  = home_url( '/login/' );
$page_viewed = basename($_SERVER['REQUEST_URI']);

if( $page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {
wp_redirect($login_page);
exit;
}}
add_action('init','redirect_login_page');

function login_failed() {
$login_page  = home_url( '/login/' );
wp_redirect( $login_page . '?user-login=failed' );
exit;
}
add_action( 'wp_login_failed', 'login_failed' );

function verify_username_password( $user, $username, $password ) {
$login_page  = home_url( '/login/' );
if( $username == "" || $password == "" ) {
wp_redirect( $login_page . "?user-login=empty" );
exit;
}}
add_filter( 'authenticate', 'verify_username_password', 1, 3);

function logout_page() {
$login_page  = home_url( '/login/' );
wp_redirect( $login_page . "?user-login=false" );
exit;
}
add_action('wp_logout','logout_page');

I would love some help adding a simple "plus minus question" to this and until that question is answered, inactivate the login button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy