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',
相关推荐
漏刻有时20 小时前
PHP GeoJSON转PNG地图渲染程序开发笔记、源码解读、问题复盘与整改方案
android·笔记·php
-SOLO-21 小时前
解决VMware 显示比例被重置的问题
android
always_TT1 天前
【Python 日志记录:logging 模块入门】
开发语言·python·php
alexhilton1 天前
探究Android Views、Flutter和Compose如何渲染你的UI
android·kotlin·android jetpack
Lesile1 天前
Android:Hilt框架入门 · 在ViewUI和ComposeUI下的应用
android·android jetpack
Immortal__y1 天前
Upload-Labs 关卡防御方式
php
用户423816229071 天前
Android 16 WebView 页面顶部挖孔/通知栏不能显示UI问题排查
android
weixin_727535621 天前
Loop 已死,Graph 新生:AI 工作流的范式革命
android·人工智能·rxjava
严同学正在努力1 天前
从备份到恢复:我用 30 分钟恢复了误删的核心业务表
android·java·数据库·ai
JonLee20201 天前
适配 Yii 3.0,php-casbin/yii-permission 3.0 正式发布
安全·php·rbac·yii·权限·casbin