本文整理汇总了PHP中FOS\UserBundle\Model\UserInterface::getUsernameCanonical方法的典型用法代码示例。如果您正苦于以下问题:PHP UserInterface::getUsernameCanonical方法的具体用法?PHP UserInterface::getUsernameCanonical怎么用?PHP UserInterface::getUsernameCanonical使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FOS\UserBundle\Model\UserInterface
的用法示例。
在下文中一共展示了UserInterface::getUsernameCanonical方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enforceUsername
/**
* Enforces that the given user will have an username
* @param \FOS\UserBundle\Model\UserInterface $user
*/
public function enforceUsername(UserInterface $user)
{
$current = $user->getUsernameCanonical();
if (is_null($current) || strlen($current) == 0) {
$email = explode('@', $user->getEmailCanonical(), 2);
$username = $email[0];
if (!UsernameValidator::isUsernameValid($username)) {
$username = UsernameValidator::getValidUsername();
}
$newUsername = $this->getNextAvailableUsername($username);
$user->setUsername($newUsername);
$this->updateCanonicalFields($user);
}
}
示例2: updatePassword
/**
* {@inheritdoc}
*/
public function updatePassword(UserInterface $user)
{
if (0 !== strlen($password = $user->getPlainPassword())) {
$passwordDigesta = md5($user->getUsernameCanonical() . ':SabreDAV:' . $password);
$salt = $user->getSalt();
$salted = $password . '{' . $salt . '}';
$digest = hash('sha512', $salted, true);
for ($i = 1; $i < 5000; $i++) {
$digest = hash('sha512', $digest . $salted, true);
}
$encodedPassword = base64_encode($digest);
$user->setPassword($encodedPassword);
$user->setPasswordDigesta($passwordDigesta);
$user->eraseCredentials();
}
}