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...
}

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
- 2 回答
- 0 關注
- 138 瀏覽
添加回答
舉報