本文整理汇总了PHP中Nette\Security\Passwords::hash方法的典型用法代码示例。如果您正苦于以下问题:PHP Passwords::hash方法的具体用法?PHP Passwords::hash怎么用?PHP Passwords::hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Security\Passwords
的用法示例。
在下文中一共展示了Passwords::hash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
/**
* Adds new user.
* @param string
* @param string
* @return void
*/
public function add($username, $password)
{
$user = new Entities\UserEntity();
$user->setUsername($username);
$user->setPassword(Passwords::hash($password));
$this->userRepository->save($user);
}
示例2: registerFormSucceeded
public function registerFormSucceeded($form, $values)
{
$hash = \Nette\Security\Passwords::hash($values['password']);
$reguser = $this->database->table('users')->insert(array('username' => $values->username, 'password' => $hash, 'email' => $values->email));
$this->flashMessage("Gratulujeme. Boli ste úspešne zaregistrovaný. Môžte sa prihlásiť do aplikácie.", 'success');
$this->redirect('Sign:in');
}
示例3: editUser
public function editUser($values, $user_id)
{
// $temp = $this->database->table('user')->where('email = ?', $values->email)->fetch();
$row = $this->database->table('user')->where('id', $user_id)->fetch();
if (!NS\Passwords::verify($values->oldPassword, $row->password)) {
// throw new NS\AuthenticationException('Špatné heslo.');
$check = 0;
} else {
if ($values->newPassword != NULL) {
$this->database->table('user')->where('id', $user_id)->update(['password' => Passwords::hash($values->newPassword)]);
}
if ($values->username != NULL) {
$this->database->table('user')->where('id', $user_id)->update(['username' => $values->username]);
}
$check = 1;
}
// $check = 0;
// if ((!$temp)) $check = 1;
// if ($check) {
// $this->database->table('user')->where('id', $user_id)->update([
// 'username' => $values->username,
// 'password' => Passwords::hash($values->newPassword),
// ]);
//
// /*$mail = new Message;
// $mail->setFrom('BrNOC bot <bot@brnoc.cz>')
// ->addTo($values->email)
// ->setSubject('Potvrzení příhlášení')
// ->setBody("Byl jsi přihlášen jako účastník BrNOCi 2015. \n \nBrNOC tým");*/
// }
return $check;
}
示例4: authenticate
/**
* Performs an authentication.
* @param array $credentials (string $username, string $password)
* @return Nette\Security\Identity
* @throws Nette\Security\AuthenticationException
*/
public function authenticate(array $credentials)
{
list($username, $password) = $credentials;
$row = $this->database->table('user')->where('username', $username)->fetch();
if (!$row) {
throw new Security\AuthenticationException('Uživatel s tímto jménem neexistuje.', self::IDENTITY_NOT_FOUND);
} elseif (!Security\Passwords::verify($password, $row->password)) {
throw new Security\AuthenticationException('Nesprávné heslo.', self::INVALID_CREDENTIAL);
} elseif (!$row->active) {
throw new Security\AuthenticationException('Účet není aktivovaný.', self::NOT_APPROVED);
} elseif (Security\Passwords::needsRehash($row->password)) {
$row->update(array('password' => Security\Passwords::hash($password)));
}
$arr = $row->toArray();
unset($arr['password']);
$roles = $row->related('privilege')->fetch()->toArray();
unset($roles['user_id']);
//adds privileges
array_walk($roles, function (&$value, $key) use(&$roles) {
if ($value != NULL) {
$value = $key . ' - ' . $value;
}
});
return new Security\Identity($row->id, $roles, $arr);
}
示例5: onSuccess
public function onSuccess()
{
$v = $this->values;
$user = $this->orm->users->getByEmail($v->email);
if ($user && $user->registered) {
$this->addError('duplicate');
return;
}
if (!$user) {
$user = new User();
$user->email = $v->email;
$this->orm->users->attach($user);
}
$user->gender = $v->gender;
$user->setNames($v->name);
$user->registered = TRUE;
$plainHash = Passwords::hash($v->password);
$user->password = $this->aes->encrypt($plainHash);
$this->orm->flush();
/** @var Auth $presenter */
$presenter = $this->presenter;
$presenter->user->login(new Identity($user->id));
$this->iLog('auth.registration.password', ['entropy' => $this->entropy->compute($v->password, $user)]);
$presenter->onLogin($user, TRUE);
}
示例6: hashPassword
public function hashPassword(ArrayHash $values)
{
if ($values->password) {
$values->password = Passwords::hash($values->password);
} else {
unset($values->password);
}
}
示例7: add
/**
* @param \stdClass $user
* @throws DuplicateNameException
*/
public function add(\stdClass $user)
{
try {
$this->userModel->add(['username' => $user->username, 'email' => $user->email, 'password' => Passwords::hash($user->password), 'first_name' => $user->firstName, 'last_name' => $user->lastName]);
} catch (UniqueConstraintViolationException $e) {
throw new DuplicateNameException();
}
}
示例8: update
public function update($userID, $login, $password, $email)
{
try {
$this->database->table(self::TABLE_NAME)->get($userID)->update(array(self::COLUMN_NAME => $login, self::COLUMN_PASSWORD_HASH => Passwords::hash($password), self::COLUMN_EMAIL => $email));
} catch (Nette\Database\UniqueConstraintViolationException $e) {
throw new DuplicateNameException();
}
}
示例9: renderDefault
/**
* @param string|null $password
*/
public function renderDefault($password = NULL)
{
if (!empty($password)) {
$this->template->hash = \Nette\Security\Passwords::hash($password);
}
$this->setLayout(FALSE);
$this->template->setFile(__DIR__ . '/template.latte');
}
示例10: add
/**
* Adds new user.
*
* @param string
* @param string
*/
public function add($username, $password)
{
try {
$this->connection->query('INSERT INTO [' . table(self::TABLE_NAME) . ']', array(self::COLUMN_NAME => $username, self::COLUMN_PASSWORD_HASH => Passwords::hash($password)));
} catch (Exception $e) {
throw new DuplicateNameException();
}
}
示例11: uprav
/**
* Upraví
* @param int
* @param string
* @param string
* @param string
* @return int
*/
public function uprav($id, $jmeno, $heslo, $role)
{
$u = array(self::COLUMN_NAME => $jmeno, self::COLUMN_ROLE => $role);
if ($heslo) {
$u[self::COLUMN_PASSWORD_HASH] = Passwords::hash($heslo);
}
return $this->database->table(self::TABLE_NAME)->where(self::COLUMN_ID, (int) $id)->update($u);
}
示例12: add
/**
* Adds new user.
* @param string
* @param string
* @param string
* @return void
* @throws DuplicateNameException
*/
public function add($username, $password, $role = 'guest')
{
try {
$this->db->insert(self::TABLE_NAME, [self::COLUMN_NAME => $username, self::COLUMN_PASSWORD_HASH => Passwords::hash($password), self::COLUMN_ROLE => $role])->execute();
} catch (Nette\Database\UniqueConstraintViolationException $e) {
throw new DuplicateNameException();
}
}
示例13: add
/**
* Adds new user.
* @param string
* @param string
* @param string
* @param int
* @return void
*/
public function add($sUserName, $sPassword, $sEmail, $iRole)
{
try {
$this->oDatabase->table(self::TABLE_NAME)->insert(array(self::COLUMN_NAME => $sUserName, self::COLUMN_PASSWORD_HASH => Passwords::hash($sPassword), self::COLUMN_MAIL => $sEmail, self::COLUMN_TYP => $iRole));
} catch (Nette\Database\UniqueConstraintViolationException $oException) {
throw new DuplicateNameException();
}
}
示例14: add
/**
* Adds new user.
* @param string
* @param string
* @param string
* @return void
* @throws DuplicateNameException
*/
public function add($username, $email, $password)
{
try {
$this->database->table(self::TABLE_NAME)->insert([self::COLUMN_NAME => $username, self::COLUMN_PASSWORD_HASH => Passwords::hash($password), self::COLUMN_EMAIL => $email]);
} catch (Nette\Database\UniqueConstraintViolationException $e) {
throw new DuplicateNameException();
}
}
示例15: add
/**
* @param string $username
* @param string $password
* @param string $fullname
*/
public function add($username, $password, $fullname)
{
$user = new User();
$user->setUsername($username);
$user->setPassword(Passwords::hash($password));
$user->setFullname($fullname);
$this->userDao->safePersist($user);
}