本文整理汇总了PHP中UserHelper::getCryptedPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP UserHelper::getCryptedPassword方法的具体用法?PHP UserHelper::getCryptedPassword怎么用?PHP UserHelper::getCryptedPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserHelper
的用法示例。
在下文中一共展示了UserHelper::getCryptedPassword方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: installAdmin
/**
* Installation of first Offiria admin user
*/
public function installAdmin(&$db, $username, $password, $email, $configs)
{
$salt = UserHelper::genRandomPassword(32);
$crypt = UserHelper::getCryptedPassword($password, $salt);
$password = $crypt . ':' . $salt;
//$table = $configs->getValue('dbprefix') . 'users';
$table = $this->_prefix . 'users';
$date = date("Y-m-d H:i:s");
$query = "INSERT INTO `{$table}` (id, name, username, email, password, sendEmail, registerDate, lastvisitDate, params) " . "VALUES(42, '{$username}', '{$username}', '{$email}', '{$password}', 1, '{$date}', '{$date}', '')";
try {
$stmt = $db->prepare($query);
$stmt->execute();
} catch (RuntimeException $e) {
return false;
}
// install anon user
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = '';
for ($i = 0; $i < 8; $i++) {
$n = rand(0, count($alphabet) - 1);
$pass[$i] = $alphabet[$n];
}
$pass = $pass . ':' . $salt;
$query = "INSERT INTO `{$table}` (id, name, username, email, password, sendEmail, block, registerDate, lastvisitDate, params) " . "VALUES(43, 'Anonymous', 'anon', 'anon@anon.com', '{$pass}', 1, 1, '{$date}', '{$date}', '')";
try {
$stmt = $db->prepare($query);
$stmt->execute();
} catch (RuntimeException $e) {
return false;
}
return true;
}