0

I have a working site where users are logging into using their email/username and password. Every user has a usermeta field with an unique code.

I have to modify the login page in order to let them log into the app using this code. The login form should have just a "Code" field.

The site is also serving as an API. I'm using WP-REST API and JWT Authentication for WP-API for authentication.

I have to modify the authentication process for the website login form and the api endpoint.

Is there some way to achieve that?

1

Ok seems like you have a few moving parts here...

  1. You want to add a new meta field (unique code) to the user meta for all users

  2. You want to modify the default login form by adding an extra field... a unique code field

  3. This unique code field should allow the user to login if they have provided the same unique code in the login form


  1. I'm going to assume you've added this meta, if not, I suggest using carbon-fields to achieve this

    Container::make( 'user_meta', 'Login Meta' )
    ->add_fields( array(
        Field::make( 'text', 'unique_code', 'Unique Code' ),
    ));
    

  1. To hook into the login form you'll want to make use of the login_form action

    add_action( 'login_form', function(){
      echo '<input type="text" name="unique_code" placeholder="Enter your unique code here" />';
    });
    

  1. Authenticating with this unique code field

you'll then want to look at the authenticate filter which you can hook into to force authenticate the user based on this posted "unique_code" field

 add_filter( 'authenticate', function( $user, $username, $password ){

      //do the check for the unique_code field here, 
      //which should be available in the $_POST object


     return $user;
  });

hope this helps, cheers

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.