Support » Fixing WordPress » Authenticate WooCommerce custom login fields.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Which plugin are you using to create the custom login fields? If not a plugin, can you share the code you’ve written?

    You will likely get more replies if you provide more detail.

    Thread Starter Shehryar Tanoli

    (@shehryarkhan)

    @littlepackage Thanks for your response I have found a solution..

    Thread Starter Shehryar Tanoli

    (@shehryarkhan)

    Below is the solution I found. It might be helpful for someone else

    //login authentication
    function login_auth($user)
    {
    $login_otp = wc()->session->get(‘login_otp’);

    if( empty($_POST[‘otp_login_field’])){

    remove_action(‘authenticate’, ‘wp_authenticate_username_password’, 20);
    $user = new WP_Error( ‘denied’, __(” Otp field is empty “));
    }
    elseif($_POST[‘otp_login_field’] != $login_otp){
    remove_action(‘authenticate’, ‘wp_authenticate_username_password’, 20);
    $user = new WP_Error( ‘denied’, __(” Invalid otp “));

    }

    return $user;
    }//login authentication ends here

    add_filter(‘woocommerce_process_login_errors’, array($this,’login_auth’),10,3);

    
    // login authentication
    function my_custom_otp_login_auth( $validation_error, $login $password ) {
    
        $login_otp = WC()->session->get( 'login_otp' );
    
        if ( empty( $_POST['otp_login_field'] ) ) {
            remove_action( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
            $validation_error = new WP_Error( 'denied', 'OTP field is empty' );
        } else if ( isset( $login_otp ) && $_POST['otp_login_field'] != $login_otp ) {
            remove_action( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
            $validation_error = new WP_Error( 'denied', 'Invalid OTP');
        }
        return $validation_error;
    }
    add_filter( 'woocommerce_process_login_errors', 'my_custom_otp_login_auth', 10, 3 );

    I tidied up your code so someone might be able to use it as-is, but they should know this could use more work to be safe & ready-to-use. It’d be even more helpful to the community if you shared which plugin you are using to create the custom login fields… I looked a bit and still can’t guess which plugin this works with. If not a plugin, then maybe share the code for the ‘otp_login_field’ field(s).

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.