第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將數(shù)據(jù)庫中的普通密碼轉換為Laravel加密密碼

將數(shù)據(jù)庫中的普通密碼轉換為Laravel加密密碼

PHP
波斯汪 2022-08-05 10:37:29
我有一個名為“users”的表,其中我有來自用戶的用戶名和密碼。密碼為純文本格式。現(xiàn)在,我使用Laravel 6.0和Auth創(chuàng)建了一個新網(wǎng)站。因此,如果用戶想要登錄我的網(wǎng)站,我需要將我的密碼純文本轉換為加密的新密碼。我如何從我的身份驗證中獲取“鹽”,以及從我的普通密碼和“鹽”中獲取加密密碼的工具。原因是因為我在users表中創(chuàng)建了一個新列,因此我想將使用查詢加密的密碼放在那里。運行change_command
查看完整描述

2 回答

?
白豬掌柜的

TA貢獻1893條經(jīng)驗 獲得超10個贊

Laravel立面提供安全的Bcrypt和Argon2哈希來存儲用戶密碼。Hash


$password = Hash::make('plain-text-password');

該函數(shù)使用 Bcrypt 對給定值進行哈希處理。您可以將其用作立面的替代方案:bcryptHash


$password = bcrypt('plain-text-password');

我如何從我的身份驗證中獲取“鹽”,以及從我的普通密碼和“鹽”中獲取加密密碼的工具。


根據(jù)哈希驗證密碼

該方法允許您驗證給定的純文本字符串是否與給定的哈希相對應。check


if (Hash::check('plain-text-password', $hashedPassword)) {

    // The passwords match...

}

更新

您可以使用 Command 或創(chuàng)建路由來更改現(xiàn)有客戶的“純文本”密碼。


創(chuàng)建命令應用程序/控制臺/命令/更改密碼.php


<?php


namespace App\Console\Commands;


use App\User;

use Illuminate\Console\Command;

use Illuminate\Support\Facades\Hash;


class ChangePassword extends Command

{

    /**

     * The name and signature of the console command.

     *

     * @var string

     */

    protected $signature = 'change-password';


    /**

     * The console command description.

     *

     * @var string

     */

    protected $description = 'Plain-text password changer';


    /**

     * Create a new command instance.

     *

     * @return void

     */

    public function __construct()

    {

        parent::__construct();

    }


    /**

     * Execute the console command.

     *

     * @return mixed

     */

    public function handle()

    {

        $users = User::get();


        foreach ($users as $user) {

            if (Hash::needsRehash($user->password)) {

                $user->password = Hash::make($user->password);

                $user->save();

            }

        }


        $this->info('Done..');

    }

}

用法:

php artisan change-password

運行命令后,您可以嘗試通過路由登錄。Auth::routes()


或手動對用戶進行身份驗證

if (Auth::attempt($credentials)) {

    // Authentication passed...


查看完整回答
反對 回復 2022-08-05
?
慕蓋茨4494581

TA貢獻1850條經(jīng)驗 獲得超11個贊

您必須創(chuàng)建一個函數(shù)來首先將數(shù)據(jù)庫密碼更新為加密密碼。


在 Web 上.php類似的東西,并在瀏覽器上訪問 /password-updator


Route::get('/password_updator', function() {

 $allusers = \DB::table('users')->get();

 foreach($users as $user) {

  $user->password = bcrypt($user->password);

  $user->save();

}

});

在繼續(xù)之前,請確保備份您的數(shù)據(jù)庫!


或者,創(chuàng)建一個名為“password_hashed第一個 onn 用戶”表的新列,并將其更新為試驗。


https://laravel.com/docs/5.4/helpers#method-bcrypt


查看完整回答
反對 回復 2022-08-05
  • 2 回答
  • 0 關注
  • 138 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號