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',
相关推荐
solo_992 小时前
Android Event 日志完全指南
android
孙晓鹏life2 小时前
MySQL-Seconds_behind_master的精度误差
android·mysql·adb
雨白3 小时前
C 语言文件操作核心
android
m0_738120723 小时前
PHP代码审计基础——超全局变量(三)
开发语言·安全·网络安全·php
鱼儿也有烦恼4 小时前
01.搭建Android Studio开发环境
android·android studio
m0_738120725 小时前
PHP代码审计基础——面向对象(四)
android·开发语言·网络·安全·github·php
2601_963771375 小时前
10 Best PHP Media CMS and Scripts for Web Creators in 2026
开发语言·前端·php
Coffeeee7 小时前
搞Android的怎么可能搞不懂Context Engineering?
android·人工智能·ai编程
Carson带你学Android7 小时前
Gemini Nano 开发实战:让你的App轻松拥有端侧 AI 功能
android·ai编程
TDengine (老段)8 小时前
TDengine SMA 索引 — 块级/文件级统计索引
android·大数据·服务器·数据库·人工智能·时序数据库·tdengine