最简单的方法,自己实现密码比较的代码: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文件,里面代码如下:

  1. <?php
  2. namespace App\Libraries;
  3. use Illuminate\Contracts\Hashing\Hasher;
  4. class MD5 implements Hasher
  5. {
  6. /**
  7. * Hash the given value.
  8. *
  9. * @param string $value
  10. *
  11. * @return array $options
  12. * @return string
  13. */
  14. public function make($value, array $options = [])
  15. {
  16. return md5($value);
  17. }
  18. /**
  19. * Check the given plain value against a hash.
  20. *
  21. * @param string $value
  22. * @param string $hashedValue
  23. * @param array $options
  24. *
  25. * @return bool
  26. */
  27. public function check($value, $hashedValue, array $options = [])
  28. {
  29. if(empty($hashedValue)){
  30. return true;
  31. }
  32. return $this->make($value) === $hashedValue;
  33. }
  34. /**
  35. * Check if the given hash has been hashed using the given options.
  36. *
  37. * @param string $hashedValue
  38. * @param array $options
  39. *
  40. * @return bool
  41. */
  42. public function needsRehash($hashedValue, array $options = [])
  43. {
  44. return false;
  45. }
  46. }

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’,