zoukankan      html  css  js  c++  java
  • 自定义UserProvider,更改验证方法

     新建UserProvider,如果继承EloquentUserProvider,注入model是必须的,或者去继承interface,自己实现一些方法

    use IlluminateAuthEloquentUserProvider;
    use IlluminateContractsAuthAuthenticatable as UserContract;
    
    class MyUserProvider extends EloquentUserProvider
    {
        protected $model;
    
        public function __construct($model)
        {
            $this->model = $model;
        }
       
    
        public function validateCredentials(UserContract $user, array $credentials)
        {
            $plain = $credentials['password'];
    
            $secret = $user->getAuthPassword();
    
            if (password_verify($plain, $secret)){
                return true;
            }elseif ($this->think_ucenter_md5($plain) === $secret){
                $user->password = password_hash($plain, PASSWORD_DEFAULT);
                $user->save();
                return true;
            }
        }
    
        private function think_ucenter_md5($str)
        {
            return md5(sha1($str) . 'VvKl0QZBE7nao5xtXqGkWrMPchRbHdwmLF361izT');
        }
    
    
    }

    appProvidersAuthServiceProvider.php 中进行注册

        public function boot(GateContract $gate)
        {
            $this->registerPolicies($gate);
    
            Auth::provider('my', function($app) {
                // 返回IlluminateContractsAuthUserProvider实例...
                return new MyUserProvider(User::class);
            });
        }

    更改config/auth.php

        'providers' => [
            'users' => [
                'driver' => 'my',
                'model' => myUserUser::class,
            ],
  • 相关阅读:
    主键索引就是聚集索引吗?
    聚集索引以及非聚集索引
    IO阻塞模型、IO非阻塞模型、多路复用IO模型
    Log4j的使用说明
    前置机是什么
    转:图文理解区块链
    DQL、DML、DDL、DCL全名是啥?
    OLAP和OLTP的区别
    JAVA之运算符优先级
    JAVA之异常处理(一)
  • 原文地址:https://www.cnblogs.com/fenle/p/5650882.html
Copyright © 2011-2022 走看看