本文整理匯總了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;
}