I want to replace the default bcrypt (password) with MD5 (password+salt), without changing the vendor file, you can add only one serviceprovider to replace the original. So I wrote a addsalthasher, but found that in the Make method can not get $salt, is there any way to get this value?
namespace App\Services;use RuntimeException;use Illuminate\Contracts\Hashing\Hasher as HasherContract;class AddSaltHasher implements HasherContract{public function make($value, array $options = []){ $hash = md5($value.$salt);//<-无法获取数据库中存放的salt if ($hash === false) { throw new RuntimeException('addsalt hashing not supported.'); } return $hash;}public function check($value, $hashedValue, array $options = []){ if (strlen($hashedValue) === 0) { return false; } $value = self::make($value); if($value!=$hashedValue){ return false; } return true;}public function needsRehash($hashedValue, array $options = []){ return false;}}
Reply content:
I want to replace the default bcrypt (password) with MD5 (password+salt), without changing the vendor file, you can add only one serviceprovider to replace the original. So I wrote a addsalthasher, but found that in the Make method can not get $salt, is there any way to get this value?
namespace App\Services;use RuntimeException;use Illuminate\Contracts\Hashing\Hasher as HasherContract;class AddSaltHasher implements HasherContract{public function make($value, array $options = []){ $hash = md5($value.$salt);//<-无法获取数据库中存放的salt if ($hash === false) { throw new RuntimeException('addsalt hashing not supported.'); } return $hash;}public function check($value, $hashedValue, array $options = []){ if (strlen($hashedValue) === 0) { return false; } $value = self::make($value); if($value!=$hashedValue){ return false; } return true;}public function needsRehash($hashedValue, array $options = []){ return false;}}
You define a class yourself and then set a static method to do this thing will be more flexible, you say. If you want to ensure a higher level of security, we recommend that you do not use MD5, but use the SHA-2 version. PHP's hash extension provides a method (http://php.net/manual/zh/function.hash.php) that can be used SHA-2