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',
相关推荐
幽络源小助理15 小时前
Kratos Typecho 主题源码:完美移植 WordPress 版
php·源码
hnlgzb15 小时前
请详细解释一下MVVM这个设计模型
android·kotlin·android jetpack·compose
jwn99916 小时前
PHP vs C:语言特性与应用场景对比
c语言·开发语言·php
❀͜͡傀儡师16 小时前
手机变AI助手:ApkClaw让闲置安卓机“再就业”
android·人工智能·智能手机
我还为发觉16 小时前
2026 PHP入门到精通全实操(环境部署+框架实战)
开发语言·php
lxysbly16 小时前
鸿蒙FC红白机模拟器app下载
android·华为·harmonyos
陆业聪16 小时前
SystemUI 里做 Launcher App 列表:四种方案的 Framework 原理与工程取舍
android·framework·systemui·launcher
2501_9151063217 小时前
iOS 多技术栈混淆实现,跨平台 App 混淆拆解与组合
android·ios·小程序·https·uni-app·iphone·webview
ii_best17 小时前
自动化开发软件[按键精灵] 安卓/iOS脚本,变量作用域细节介绍
android·运维·ios·自动化