如何使用 slim2 和 eloquent 对密码进行哈希处理

How to hash password on saving using slim2 and eloquent

我正在为用户注册,因为我希望使用 eloquent 和 slim 以哈希格式存储密码,但我收到哈希未找到错误 This is the error image

在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.phpclass

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

在上面的代码中,我无法将密码散列为 store.Can 谁能告诉我如何将密码存储为散列..

尝试替换这一行:

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

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