search

Home  >  Q&A  >  body text

laravel - laravle5.0.22 How to modify the verification encryption method (change to MD5 verification)

auth Login verification no longer uses MD5. How to add an MD5 verification without modifying the source code. Please give a detailed introduction.

PHP中文网PHP中文网2750 days ago603

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-05-16 16:57:43

    Is the questioner talking about encrypted passwords?

    If yes, you can add this User.php in

    
    public function setPasswordAttribute($password)
        {
            $this->attributes['password'] = md5($password);
        }

    ==================================================== ==============

    Modified part:

    1. In app/下创建一个MD5/文件夹。里面创建一个MD5Hasher类(MD5Hasher.php):

    class MD5Hasher implements Illuminate/Contracts/Hashing/Hasher {
    
        /**
         * Hash the given value.
         *
         * @param  string  $value
         * @return array   $options
         * @return string
         */
        public function make($value, array $options = []) {
            return md5($value);
        }
    
        /**
         * Check the given plain value against a hash.
         *
         * @param  string  $value
         * @param  string  $hashedValue
         * @param  array   $options
         * @return bool
         */
        public function check($value, $hashedValue, array $options = []) {
            return $this->make($value) === $hashedValue;
        }
    
        /**
         * Check if the given hash has been hashed using the given options.
         *
         * @param  string  $hashedValue
         * @param  array   $options
         * @return bool
         */
        public function needsRehash($hashedValue, array $options = []) {
            return false;
        }
    
    }
    

    make your provider

    Command line:

    php artisan make:provider MD5HashServiceProvider

    Write in the register() method of this file:

    public function register()
        {
            $this->app['hash'] = $this->app->share(function () {
                return new MD5Hasher();
            });
        }
    

    Modify configuration

    config/app.php, comment the following line:

     Illuminate\Hashing\HashServiceProvider::class,

    Add yours:

    MD5HashServiceProvider::class

    Happy Hacking

    reply
    0
  • Cancelreply