Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel auth::atempt仅获取哈希密码_Php_Laravel_Laravel 5 - Fatal编程技术网

Php Laravel auth::atempt仅获取哈希密码

Php Laravel auth::atempt仅获取哈希密码,php,laravel,laravel-5,Php,Laravel,Laravel 5,我已经在CRM中创建了帐户,并在其中哈希了密码 $account->password = bcrypt($password); 然后在我的网站上,我创建了一些守卫和提供者: 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [

我已经在CRM中创建了帐户,并在其中哈希了密码

$account->password = bcrypt($password);
然后在我的网站上,我创建了一些守卫和提供者:

 'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
        'business' => [
            'driver' => 'session',
            'provider' => 'business'
        ]
    ],

 'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\Eloquent\Account::class,
        ],
        'business' => [
            'driver' => 'eloquent',
            'model'  => App\Models\Eloquent\BusinessAccounts::class
        ]
    ],
然后尝试使用guard business登录帐户:

public function login(BusinessLoginRequest $request)
    {
        $orgNumber = $request->input('orgNumber');
        $password = $request->input('password');

        if(Auth::guard('business')->attempt(['orgNumber' => $orgNumber, 'password' => $password ])) {
                var_dump(\auth('business')->user());
        }

    }
我的模型看起来像:

class BusinessAccounts extends Model implements Authenticatable
{
    use \Illuminate\Auth\Authenticatable;

    protected $table = 'business_accounts';

    protected $fillable =
        [
            'orgNumber', 'password'
        ];

    public $timestamps = false;

}
但当我尝试登录并使用未散列的密码转储用户时,我有一个空白屏幕,当我尝试从数据库中输入散列的密码时,我可以看到业务帐户模型。 我的代码有什么问题? 我如何理解thad Auth::atempt?只需用db password检查登录密码中的值,当然,它们并不相同。 我读了很多指南和文章,但没有发现错误,
我知道这很简单,但我看不出来。

在使用
尝试
函数时,您不需要使用
bcrypt
。由于您已经在数据库中存储了散列密码,所以只需比较通过
trunt
函数完成的密码即可

因此,只需删除
bcrypt
并按原样传递即可

$account->password = $password;

如果找到用户,则数据库中存储的哈希密码将被删除 与通过传递给方法的密码值进行比较 数组。您不应该散列指定为密码的密码 值,因为框架将在 将其与数据库中的哈希密码进行比较


我只在通过CRM将模型保存在DB中时才使用bcrypt。我在登录时不使用bcrypt