Error message here!

Hide Error message here!

忘记密码?

Error message here!

请输入正确邮箱

Hide Error message here!

密码丢失?请输入您的电子邮件地址。您将收到一个重设密码链接。

Error message here!

返回登录

Close

Laravel password authentication changed to MD5

wx5bffdbaf11b62 2021-07-26 11:16:37 阅读数:2 评论数:0 点赞数:0 收藏数:0

Application scenarios : The old system uses TP frame , It's using MD5 encryption , Current use Laravel Framework refactoring

1. newly build MD5Hasher Class file , Put it in App/Helpers Next

<?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. Create service provider

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. stay app/config.php Of prociders Lieutenant general

Illuminate\Hashing\HashServiceProvider::class,

Replace with the following or comment out the above

\App\Providers\MD5HashServiceProvider::class,

4. Found for project composer.json Under the document autoload Array Add classmap

 "classmap": [
"app/Helpers/MD5Hasher"
],

 

5. perform

composer dumpautoload

6. Finally, you can test

Copyright statement
In this paper,the author:[wx5bffdbaf11b62],Reprint please bring the original link, thank you

编程之旅,人生之路,不止于编程,还有诗和远方。
阅代码原理,看框架知识,学企业实践;
赏诗词,读日记,踏人生之路,观世界之行;