zoukankan      html  css  js  c++  java
  • laravel 5.5 更改默认的密码加密方法

    laravel 由于很多数据是导入的,采用的是md5加密密码,但是laravel 默认的是使用bcrypt加密,所以需要更改,需要重写Auth中的attempt方法中的密码加密方法。

            $request_params=$request->only(['username','password']);
           /*attempt默认使用bcrypt加密*/
            if(Auth::guard('chatService')->attempt($request_params))
            {
                return response()->json(['msg'=>'登陆成功','code'=>200]);
            }else
                {
                    return  response()->json(['msg'=>'登陆失败','code'=>400]);
                }
    

      

    第一步:在vendorlaravelframeworksrcIlluminateHashing 新建Md5Hasher文件写入以下内容、

    <?php
    
    namespace IlluminateHashing;
    
    use RuntimeException;
    use IlluminateContractsHashingHasher as HasherContract;
    /*增加MD5加密*/
    class Md5Hasher implements HasherContract
    {
    
        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);
        }
    }
    

     第二步:

     1)建立 MD5HashServiceProvider

                        

     php artisan make:provider MD5HashServiceProvider
    

     

     2)写入以下内容:

               

    <?php
    
    namespace AppProviders;
    
    use IlluminateHashingMd5Hasher;
    use IlluminateSupportServiceProvider;
    
    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']; // TODO: Change the autogenerated stub
        }
    }
    

      3)更改config/app.php

                  

    'providers' => [
            /*
             * Laravel Framework Service Providers...
    将原来的 IlluminateHashingHashServiceProvider::class更改
             */
            AppProvidersMD5HashServiceProvider::class,
    

     

    参考:https://learnku.com/articles/5963/toggle-laravel-login-default-bcrypt-encryption-validation

  • 相关阅读:
    html中滚动条的样式
    在个人机上发布web项目
    Apache与SVN的集成
    待完成
    chmod
    【转】ubuntu修改IP地址和网关的方法
    ubuntu 添加svn服务
    生成指定大小的空文件
    数码单反相机完全攻略
    【转】ubuntu subversion安装
  • 原文地址:https://www.cnblogs.com/fogwang/p/12214300.html
Copyright © 2011-2022 走看看