laravel 自定义密码验证方式

继承 EloquentUserProvider

php 复制代码
<?php
 
 
namespace App\Providers;
 
 
use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Contracts\Auth\ Authenticatable as UserContract;
 
class ApiEloquentUserProvider extends EloquentUserProvider
{
    public function validateCredentials( UserContract $user, array $credentials)
    {
 
        //这里写自己的验证规则
        $password = $user->system_encrypt($credentials['password'],$user['salt']);
        return $password == $user->getAuthPassword();
    }
}

修改App\Providers\AuthServiceProvider

php 复制代码
public function boot()
{
        $this->registerPolicies();
 
        Auth::provider('api-eloquent', function ( $app, array $config) {
            return new \App\Providers\ApiEloquentUserProvider( $app[ 'hash'], $config[ 'model']);
        });
}

然后就可以在config/auth.php里直接使用了

linux 复制代码
'driver' => 'api-eloquent',
相关推荐
小驰行动派10 分钟前
Android Studio中,使用完全免费的Ai来写APP
android·ide·android studio
cch891821 分钟前
PHP与汇编:高级与低级的终极对决
开发语言·汇编·php
cyber_两只龙宝22 分钟前
【Nginx】Nginx中location的使用方法详解
linux·运维·nginx·云原生·php·web
笔夏39 分钟前
【安卓学习之socket】socket.io-client
android·学习
用户94261184462911 小时前
Android开发实战:ListView与RecyclerView使用详解
android
梦里花开知多少1 小时前
深入解析Launcher3 中的 CellLayout
android·面试
WangJunXiang61 小时前
MySQL高可用详细解析
android·数据库·mysql
heimeiyingwang1 小时前
【架构实战】混沌工程:让系统更健壮的实践
开发语言·架构·php
cch89181 小时前
PHP vs C#:语言对比与实战选型
开发语言·c#·php
让学习成为一种生活方式1 小时前
取消“为 LAN 使用代理服务器”--随笔023
开发语言·php