Changing Laravel 5.4 password encryption and table column names

前端 未结 3 1831
孤街浪徒
孤街浪徒 2021-02-04 20:35

I am trying to integrate the auth in laravel 5.4 within an existing database where the user and password fields have other names (memberid, passwordnew_enc

3条回答
  •  臣服心动
    2021-02-04 21:05

    Alright I got it

    app\User.php

    public function setPasswordAttribute($value)
    {
        $this->attributes['password'] = md5($value);
    }
    
    public function getAuthPassword()
    {
        return $this->passwordnew_enc;
    }
    
    public function getAuthIdentifierName()
    {
        return 'memberid';
    }
    

    app\Http\Controllers\Auth\LoginController.php

    public function username()
    {
        return 'memb___id';
    }
    

    config\app.php

        // Illuminate\Hashing\HashServiceProvider::class,
        App\Providers\MD5HashServiceProvider::class,
    

    app\Providers\MD5HashServiceProvider.php

    app->singleton('hash', function () {
                return new \MD5Hasher;
            });
        }
        /**
         * Get the services provided by the provider.
         *
         * @return array
         */
        public function provides()
        {
            return ['hash'];
        }
    }
    

    lib\MD5Hasher\MD5Hasher.php

    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 = array())
        {
            return false;
        }
    }
    

    composer.json

    ...
    "autoload": {
        "classmap": [
            ...
            "app/Lib"
        ],
     ...
    

提交回复
热议问题