簡體   English   中英

如何在使用slim2和雄辯的保存時對密碼進行哈希處理

[英]How to hash password on saving using slim2 and eloquent

我正在為用戶注冊,因為我希望使用雄辯而苗條的密碼以哈希格式存儲密碼,但是我發現哈希未找到錯誤, 這是錯誤圖像

在config.php中

$database = [
'driver'    => 'mysql',
'host'      => '127.0.0.1',
'database'  => 'onboard',
'username'  => 'root',
'password'  => 'rootpwd',
'charset'   => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix'    => '',
];
use Illuminate\Support\Facades\Facade;
use Illuminate\Database\Capsule\Manager as Capsule;
$Capsule = new Capsule;

$Capsule->addConnection($database);

// // Set the event dispatcher used by Eloquent models... (optional)
// use IlluminateEventsDispatcher;
// use IlluminateContainerContainer;
// $capsule->setEventDispatcher(new Dispatcher(new Container));

// Make this Capsule instance available globally via static methods... (optional)
$Capsule->setAsGlobal();

// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$Capsule->bootEloquent();

在User.php類中

function register_user($first_name,$last_name,$email,$password,$email_verification_sendtime,$email_verification_expiredtime,$created_date) {
    //echo 'hi';
    $result = array();
    $result['status'] = FAILED;
    $user = new User();
    $user->first_name = $first_name;
    $user->last_name = $last_name;
    $user->email = $email;
    $user->password = Hash::make($password);
    $user->email_verification_code = $email_verification_sendtime;
    $user->email_verification_send_datetime = $email_verification_expiredtime;
    $user->created_date = $created_date;
    if($user->save()) {
        //echo 'hi';exit;
        $result['status'] = SUCCESSFULL;
    } 
    return $result;
}

在上面的代碼中,我無法對密碼進行哈希存儲。任何人都可以說如何將密碼存儲為哈希。

嘗試替換此行:

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

$user->password = password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM