Laravel 无法更改默认加密方式?

WBOY
Release: 2016-06-06 20:26:58
Original
1396 people have browsed it

我想把默认的bcrypt(password)替换成md5(password+salt),在不更改vendor文件的情况下,只能自己添加一个ServiceProvider替换原来的。于是我自己写了一个AddSaltHasher,但是却发现在make方法中无法获取$salt,有什么办法可以获取这个值吗?

<code>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);//</code>
Copy after login
Copy after login

回复内容:

我想把默认的bcrypt(password)替换成md5(password+salt),在不更改vendor文件的情况下,只能自己添加一个ServiceProvider替换原来的。于是我自己写了一个AddSaltHasher,但是却发现在make方法中无法获取$salt,有什么办法可以获取这个值吗?

<code>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);//</code>
Copy after login
Copy after login

你自己定义一个类然后设置一个静态方法来做这件事情会更灵活,你说呢。如果要确保安全性更高,建议不要用MD5,而是用SHA-2版本。PHP的Hash扩展提供的方法(http://php.net/manual/zh/function.hash.php)可以使用SHA-2

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!