参考地址:https://laravel-china.org/articles/5963/toggle-laravel-login-default-bcrypt-encryption-validation
自己做一个备份记录
1.编写自己的hasher
<?php
namespace App\Helpers\Hasher;
use Illuminate\Contracts\Hashing\Hasher;
class MD5Hasher implements Hasher
{
public function check($value, $hashedValue, array $options = [])
{
return $this->make($value) === $hashedValue;
}
public function needsRehash($hashedValue, array $options = [])
{
return false;
}
public function make($value, array $options = [])
{
$value = env('SALT', '').$value;
return md5($value);
}
}
2.用自己的Hasher替换默认的Hasher
创建MD5HashServiceProvider
php artisan make:provider MD5HashServiceProvider
<?php
namespace App\Providers;
use App\Helpers\Hasher\MD5Hasher;
use Illuminate\Support\ServiceProvider;
class MD5HashServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->app->singleton('hash', function () {
return new MD5Hasher;
});
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
public function provides()
{
return ['hash'];
}
}
3.然后在config/app.php的providers中,将加密服务替换
Illuminate\Hashing\HashServiceProvider::class,
替换为
\App\Providers\MD5HashServiceProvider::class,
网友评论