![](/img/trans.png)
[英]Converting plain password IN database to encrypted password using laravel?
[英]Converting plain password in database to Laravel encrypted password
您必须首先创建一个函数来将您的数据库密码更新为加密密码。
在 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();
}
});
确保在继续之前备份您的数据库!
或者,您首先在用户表上创建一个名为 password_hashed 的新列并将其更新以进行实验。
Laravel Hash
门面提供安全的 Bcrypt 和 Argon2 散列来存储用户密码。
$password = Hash::make('plain-text-password');
bcrypt
函数使用 Bcrypt 散列给定的值。 你可以用它来替代Hash
门面:
$password = bcrypt('plain-text-password');
如何从我的身份验证中获取“盐”以及从我的普通密码和“盐”中获取加密密码的工具。
check
方法允许您验证给定的纯文本字符串是否对应于给定的散列。
if (Hash::check('plain-text-password', $hashedPassword)) {
// The passwords match...
}
您可以使用命令或创建路由来更改现有客户的“纯文本”密码。
创建命令app/Console/Commands/ChangePassword.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... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.