Laravel can't change the default encryption method?

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.