Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 拉威尔7/8。自定义哈希驱动程序_Php_Laravel_Laravel 7_Laravel 8 - Fatal编程技术网

Php 拉威尔7/8。自定义哈希驱动程序

Php 拉威尔7/8。自定义哈希驱动程序,php,laravel,laravel-7,laravel-8,Php,Laravel,Laravel 7,Laravel 8,我有一个旧数据库,其中密码由sha3-256散列。我正在创建一个新网站,我应该使用旧的数据库。但是Auth::trument()使用bcrypt(默认值)。如何设置哈希驱动程序sha3-256?最好使用Laravel附带的哈希算法,因为Laravel只支持Bcrypt和Argon2 但是,为了帮助您迁移到新算法,您可以在Users表中创建一个名为sha3_password的列,在其中输入旧密码,并在login中创建一个if语句来检查sha3_password是否为null,并将键入的密码与sha

我有一个旧数据库,其中密码由sha3-256散列。我正在创建一个新网站,我应该使用旧的数据库。但是Auth::trument()使用bcrypt(默认值)。如何设置哈希驱动程序sha3-256?

最好使用Laravel附带的哈希算法,因为Laravel只支持Bcrypt和Argon2

但是,为了帮助您迁移到新算法,您可以在Users表中创建一个名为sha3_password的列,在其中输入旧密码,并在login中创建一个if语句来检查sha3_password是否为null,并将键入的密码与sha3-256进行比较,如果匹配,则使用bcrypt更新Users password字段,并将sha3_密码设置为null。这样,当用户首次登录时,其密码将被更新,否则将正常登录

我用这种方法迁移了一个项目,效果很好,我的登录功能如下,基本上可以使用相同的逻辑:

    public function login(Request $request)
    {
        #Update old password after migration to new platform
        $user= User::where('email',request('email'))
            ->where('password_sha1', sha1(request('password')))
            ->where('password', null)
            ->first();
        if($user)
        {
            $user->password = bcrypt(request('password'));
            $user->password_sha1 = null;
            $user->update();
        }

        if (Auth::attempt(['email' => request('email'), 'password' => request('password'), 'status' => 1])) {
            // Authentication passed...\
            return redirect($this->redirectPath());
        }
    }

最好使用Laravel附带的哈希算法,因为Laravel只支持Bcrypt和Argon2

但是,为了帮助您迁移到新算法,您可以在Users表中创建一个名为sha3_password的列,在其中输入旧密码,并在login中创建一个if语句来检查sha3_password是否为null,并将键入的密码与sha3-256进行比较,如果匹配,则使用bcrypt更新Users password字段,并将sha3_密码设置为null。这样,当用户首次登录时,其密码将被更新,否则将正常登录

我用这种方法迁移了一个项目,效果很好,我的登录功能如下,基本上可以使用相同的逻辑:

    public function login(Request $request)
    {
        #Update old password after migration to new platform
        $user= User::where('email',request('email'))
            ->where('password_sha1', sha1(request('password')))
            ->where('password', null)
            ->first();
        if($user)
        {
            $user->password = bcrypt(request('password'));
            $user->password_sha1 = null;
            $user->update();
        }

        if (Auth::attempt(['email' => request('email'), 'password' => request('password'), 'status' => 1])) {
            // Authentication passed...\
            return redirect($this->redirectPath());
        }
    }

为了安全起见,我想用Hash::make(request('password')替换bcrypt,但这看起来很有用!为了安全起见,我想用Hash::make(request('password')替换bcrypt,但这看起来很有用!如果您不想迁移,但我怀疑您不想永远保留旧哈希,您也可以为此创建一个自定义的身份验证保护。这里的文档:您也可以为此创建一个自定义身份验证保护,如果您不想迁移,但我怀疑您不想永远保留旧哈希,这里的文档: