- <?php
- namespace App\MD5;
- use Illuminate\Contracts\Hashing\Hasher as HasherMD5;
- //后添加MD5验证
- class MD5Hasher implements HasherMD5
- {
- public function make($value, array $options = [])
- {
- return md5($value);//根据后面加密规则来设置
- }
- public function check($value, $hashedValue, array $options = [])
- {
- if(emptyempty($hashedValue)){
- return true;
- }
- return $this->make($value) === $hashedValue;
- }
- public function needsRehash($hashedValue, array $options = [])
- {
- return false;
- }
- }
2. 命令行:
php artisan make:provider MD5HashServiceProvider
在这个文件的register()方法写上:
- <?php
- namespace App\Providers;
- use Illuminate\Support\ServiceProvider;
- use App\MD5\MD5Hasher;
- class MD5HashServiceProvider extends ServiceProvider
- {
- //后添加MD5验证
- /**
- * Bootstrap the application services.
- *
- * @return void
- */
- public function boot()
- {
- //
- }
- /**
- * Register the application services.
- *
- * @return void
- */
- public function register()
- {
- $this->app->singleton('hash', function () {
- return new MD5Hasher;
- });
- }
- }
3.修改配置
config/app.php,注释下面这一行:
Illuminate\Hashing\HashServiceProvider::class,
加上你的:
App\Providers\MD5HashServiceProvider::class, //后添加MD5验证
4.测试如下:
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Auth;
- class CeshiController extends Controller
- {
- public function login(){
- Auth::attempt(['users_mobile'=>'15250735031','password'=>'']);
- dd(Auth::user());
- }
- }