7

How can I use Laravel's Passport package to authenticate a different password column.

If i want to authenticate from a different 'username' column, it can be done with the following code:

    public function findForPassport($username) {
        return $this->where('id', $username)->first();
    }

It will take Id, as the column. What if I want to use a different 'password' column. A column in the table with a different name such as 'uid_token'.

3 Answers 3

12

Adding this validateForPassportPasswordGrant method to User model did the job for me ("PasswMd" - custom column name):

public function validateForPassportPasswordGrant($password)
{
    return Hash::check($password, $this->PasswMd);
}
Sign up to request clarification or add additional context in comments.

Comments

9

There's a method the Passport/Bridge asks for called validateForPassportPasswordGrant($password) that you can override in your user model, if you don't override this it will look for a password column in your user table. I'm not entirely sure why they haven't configured it to use Authenticatable method getAuthPassword...

Comments

1

While the above solutions are great but there is another way to achieve it and it worked for me in Laravel 8.

For future readers I provide the code down here, they need to add to their models and return the custom password column like so.

    public function getAuthPassword()
    {
        return $this->PasswMd;
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.