美文网首页
Auth::attempt验证加密方式bcrypt修改为md5

Auth::attempt验证加密方式bcrypt修改为md5

作者: 杨森Janssen | 来源:发表于2018-09-28 15:12 被阅读105次

    参考地址:https://laravel-china.org/articles/5963/toggle-laravel-login-default-bcrypt-encryption-validation

    自己做一个备份记录
    1.编写自己的hasher

    <?php
    
    namespace App\Helpers\Hasher;
    
    use Illuminate\Contracts\Hashing\Hasher;
    
    class MD5Hasher implements Hasher
    {
        public function check($value, $hashedValue, array $options = [])
        {
    
            return $this->make($value) === $hashedValue;
        }
    
        public function needsRehash($hashedValue, array $options = [])
        {
            return false;
        }
    
        public function make($value, array $options = [])
        {
            $value = env('SALT', '').$value;
    
            return md5($value);
        }
    
    }
    

    2.用自己的Hasher替换默认的Hasher
    创建MD5HashServiceProvider

    php artisan make:provider MD5HashServiceProvider
    
    <?php
    
    namespace App\Providers;
    
    use App\Helpers\Hasher\MD5Hasher;
    use Illuminate\Support\ServiceProvider;
    
    class MD5HashServiceProvider extends ServiceProvider
    {
        /**
         * Bootstrap the application services.
         *
         * @return void
         */
        public function boot()
        {
            $this->app->singleton('hash', function () {
                return new MD5Hasher;
            });
        }
    
        /**
         * Register the application services.
         *
         * @return void
         */
        public function register()
        {
            //
        }
    
        public function provides()
        {
            return ['hash'];
        }
    }
    

    3.然后在config/app.php的providers中,将加密服务替换

    Illuminate\Hashing\HashServiceProvider::class,
    

    替换为

    \App\Providers\MD5HashServiceProvider::class,
    

    相关文章

      网友评论

          本文标题:Auth::attempt验证加密方式bcrypt修改为md5

          本文链接:https://www.haomeiwen.com/subject/jvlpoftx.html