例) として aes256(キー固定)に変更してみます。
app/Libs/CustomHash/CustomHasher.php を以下の内容で作成する
<?php
namespace App\Libs\CustomHash;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
class CustomHasher implements HasherContract {
public function info($hashedValue)
{
return $this->driver()->info($hashedValue);
}
public function make($value, array $options = array()) {
$key = env('CUSTOM_HASHER_AES256_KEY', false);
return openssl_encrypt($value,'aes-256-ecb',$key);
}
public function unmake($value, array $options = array()) {
$key = env('CUSTOM_HASHER_AES256_KEY', false);
return openssl_decrypt($value,'aes-256-ecb',$key);
}
public function check($value, $hashedValue, array $options = array()) {
return $this->make($value) === $hashedValue;
}
public function needsRehash($hashedValue, array $options = array()) {
return false;
}
}
app/Providers/CustomHashServiceProvider.php を以下の内容で作成する
<?php
namespace App\Providers;
use Illuminate\Hashing\HashServiceProvider;
use App\Libs\CustomHash\CustomHasher as CustomHasher;
class CustomHashServiceProvider extends HashServiceProvider
{
public function register()
{
$this->app->singleton('hash', function () {
return new CustomHasher;
});
}
}
config/app.php の変更
'providers' => [
・・・・・
App\Providers\CustomHashServiceProvider::class , // 追加
// Illuminate\Hashing\HashServiceProvider::class, // コメントアウト
・・・・・
CUSTOM_HASHER_AES256_KEY=my_aes256key
'password' => bcrypt('my-pass-word') ,
↓
'password' => \Illuminate\Support\Facades\Hash::make('my-pass-word') ,