laravel passport custom password column

纵然是瞬间 提交于 2019-12-01 04:09:47

问题


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'.


回答1:


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...




回答2:


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);
}


来源:https://stackoverflow.com/questions/40606818/laravel-passport-custom-password-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!