最简单的方法,自己实现密码比较的代码:md5输入的密码和数据库的密码对比。
然后使用Auth::loginUsingId(‘用户id’)来登录
参考文章:
http://www.jianshu.com/p/8032745fd794
http://www.bcty365.com/content-153-5886-1.html
整理:
1.在app目录下,新建一个文件Libraries,在Libraries目录下新建一个MD5.php文件,里面代码如下:
<?php
namespace App\Libraries;
use Illuminate\Contracts\Hashing\Hasher;
class MD5 implements 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 = [])
{
if(empty($hashedValue)){
return true;
}
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;
}
}
2.在Providers文件下面新建一个文件 MD5ServiceProvider.php,里面代码如下:
<?php
namespace App\Providers;
use Illuminate\Auth\EloquentUserProvider;
use App\Libraries\MD5;
use Auth;
class MD5ServiceProvider extends EloquentUserProvider
{
//继承EloquentUserProvider类,调用父类的构造函数
public function __construct($hasher, $model)
{
parent::__construct($hasher, $model);
}
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
3.在AuthServiceProvider.php文件里boot方法里添加如下代码
Auth::extend('MD5', function($app){
$model = $this->app['config']['auth.model'];
return new MD5ServiceProvider(new MD5(), $model); //这里就是直接将我们新实现的md5类传递过去
});
头部需要引用命名
use App\Libraries\MD5;
use Auth
4.修改config/auth.php里的driver,修改代码如下
‘driver’ => ‘MD5’,