如何使用slim2和eloquent来保存密码

时间:2018-03-19 08:48:03

标签: php eloquent slim slim-2

我正在为用户注册,因为我想要使用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.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;
}

在上面的代码中,我无法将密码哈希到store.Can有人说如何将密码存储为哈希值..

1 个答案:

答案 0 :(得分:0)

尝试替换此行:

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

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