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',
相关推荐
c***21291 小时前
Springboot3学习(5、Druid使用及配置)
android·学习
修炼者2 小时前
【Android 进阶】别再强转 Context 了!手把手教你优雅解耦 View 与 Activity
android·android studio
x***01062 小时前
SpringSecurity+jwt实现权限认证功能
android·前端·后端
程序员江同学2 小时前
线下活动|2025 Kotlin 中文开发者大会北京分会场
android·kotlin
李坤林3 小时前
Android Vulkan 开启VK_GOOGLE_DISPLAY_TIMING 后,一个vsync 会释放两个imageBuffer现象分析
android·vulkan
Jerry3 小时前
Compose 状态思维
android
k***45994 小时前
MySQL----case的用法
android·数据库·mysql
r***86985 小时前
Plugin ‘mysql_native_password‘ is not loaded`
android·数据库·mysql
v***59835 小时前
MySQL-mysql zip安装包配置教程
android·mysql·adb
不用89k6 小时前
Android无法区分USB摄像头是哪一个
android