本文整理汇总了PHP中Nette\Security\Passwords类的典型用法代码示例。如果您正苦于以下问题:PHP Passwords类的具体用法?PHP Passwords怎么用?PHP Passwords使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Passwords类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
/**
* Performs an authentication against e.g. database.
* and returns IIdentity on success or throws AuthenticationException
* @var array $credentials
* @return Nette\Security\IIdentity
* @throws Nette\Security\AuthenticationException
*/
public function authenticate(array $credentials)
{
list($username, $password) = $credentials;
if (is_null($password)) {
$user = $this->manager->getItem($username);
} else {
$user = $this->manager->getUserByUsername($username);
if (is_null($user->password)) {
throw new Trejjam\Authorization\User\AuthenticatorException('User has not have defined password.', Trejjam\Authorization\User\AuthenticatorException::NOT_DEFINED_PASSWORD);
} else {
if (!Nette\Security\Passwords::verify($password, $user->password)) {
throw new Trejjam\Authorization\User\AuthenticatorException('The password is incorrect.', Trejjam\Authorization\User\AuthenticatorException::INVALID_CREDENTIAL);
} else {
if (Nette\Security\Passwords::needsRehash($user->password)) {
$this->manager->changePassword($user, $password);
}
}
}
}
if ($this->manager->isEnableLogin($user)) {
$baseUserArr = (array) $this->manager->getUserInfo($user);
$baseUserArr["login_time"] = new Nette\Utils\DateTime();
$role = $this->acl->getUserRoles($user);
return new Identity($user->id, $role, $baseUserArr);
} else {
//this may not happen
throw new Trejjam\Authorization\User\AuthenticatorException();
}
}
示例2: 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;
}
示例3: 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');
}
示例4: authenticate
/**
* Performs an authentication.
* @return Nette\Security\Identity
* @throws Nette\Security\AuthenticationException
*/
public function authenticate(array $credentials)
{
if (!Passwords::verify($credentials[1], $this->database->table('option')->get('password')->value)) {
throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
}
return new Nette\Security\Identity(NULL, NULL, NULL);
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
示例8: 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();
}
}
示例9: 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);
}
示例10: hashPassword
public function hashPassword(ArrayHash $values)
{
if ($values->password) {
$values->password = Passwords::hash($values->password);
} else {
unset($values->password);
}
}
示例11: 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();
}
}
示例12: 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();
}
}
示例13: 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');
}
示例14: 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();
}
}
示例15: 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();
}
}