Laravel: Auth::attempt when login and password in different tables

40 Views Asked by At

I have a user table

userId
name

And password table

pwd_rec_id
userId
pwd_sHash

In User model

    public function userpwd() {
        return $this->hasOne(UsersPassword::class, 'userId', 'userId' );
    }

    public function getPasswordAttribute() {
        return $this->userpwd?->getAttribute('pwd_sHash');
    }

    protected $appends = [
        'password'
    ];

    public function getAuthPassword()
    {
        return $this->attributes['password']; // <<<< line xx
    }

When I try to

 Auth::attempt($credentials)

WARNING Undefined array key "password" in app\Models\User.php on line xx.

DEPRECATED password_get_info(): Passing null to parameter #1 ($hash) of type string is deprecated in vendor\laravel\framework\src\Illuminate\Hashing\AbstractHasher.php on line 15.

RuntimeException This password does not use the Bcrypt algorithm.

what a wrong with it?

When use User::find(6) result is


    = App\Models\User {#5278
        userId: 6,
        name: "Taylor",
        +password: "$2y$12$sbMA3gNT/x00xcxY0IQW5OD3hWlgH4iw1ZUi6WRDc42ylhgxNc886",

I've try to rename

return $this->attributes['password'];

to

return $this->attributes['pwd_sHash'];

and still getting an error above.

0

There are 0 best solutions below