登录加密
Auth认证加密方式并不适用于本人的原有数据,原有数据是MD5的16位加密
创建一个驱动
<?php
namespace App\Exceptions;
use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
/**
* Created by PhpStorm.
* User: hua
* Date: 2017/12/13
* Time: 15:46
*/
class TestUserProvider extends EloquentUserProvider
{
public function __construct(HasherContract $hasher, $model)
{
$this->model = $model;
$this->hasher = $hasher;
}
public function validateCredentials( UserContract $user, array $credentials)
{
$plain = $credentials['password'];
$datapassword = substr(md5($plain), 8, 16);
// return md5($plain) == $user->getAuthPassword();
return $datapassword == $user->getAuthPassword();
}
}
AuthServiceProvider
注册驱动
public function boot()
{
$this->registerPolicies();
Auth::provider('user-eloquent', function ($app, $config) {
return New TestUserProvider($app['hash'], $config['model']);
});
//
}
注册后的驱动名称为user-eloquent
,修改auth.php
中调用的的驱动
'providers' => [
'users' => [
'driver' => 'user-eloquent',
'model' => \App\Models\UniUser::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => \Encore\Admin\Auth\Database\Administrator::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
学习资源
Laravel5.1自带认证系统(Auth)改变加密方式带来的思考
如何重写Laravel 的attempt方法呢?因为加密方法是自定义的。
网友评论