How do I get WordPress login to ignore the password input if a particular username is used?

Question

I am trying to build a login where users with an account number as their username can login without a password or email.

When the user clicks login, if the username that has been input exists in the database and starts with a zero (Because I plan to make all these special accounts account numbers like 0612345), then WordPress shouldn’t bother to authenticate the password and should let the user into the account that matches that username.

I have no PHP experience but have tried to piece together code from other people’s questions:

add_filter('authenticate', 'allow_certain_users', 9999, 3);
function allow_certain_users( $user, $username, $password) {
    // If the username starts with a zero, ignore whether the password input is correct
    if (substr($username, 0, 1) == "0") {
        $user = apply_filters('authenticate', null, $username, $password);
        return $user;
    }
    return $user;
}

To explain why, these account number users will have minimal capabilities so there won’t be anything critical or personal that needs securing within each account. I would just like to avoid having to deal with the personal data of emails and passwords.

Any help appreciated!

0
Troas 2 months 0 Answers 9 views 0

Leave an answer