public createAccountWithPassword ( string $identifier, string $password, array $roleIdentifiers = [], string $authenticationProviderName = 'DefaultProvider', string $passwordHashingStrategy = 'default' ) : |
||
$identifier | string | Identifier of the account, must be unique |
$password | string | The clear text password |
$roleIdentifiers | array | Optionally an array of role identifiers to assign to the new account |
$authenticationProviderName | string | Optional name of the authentication provider the account is affiliated with |
$passwordHashingStrategy | string | Optional password hashing strategy to use for the password |
Résultat | A new account, not yet added to the account repository |
public function createAccountWithPassword($identifier, $password, $roleIdentifiers = [], $authenticationProviderName = 'DefaultProvider', $passwordHashingStrategy = 'default')
{
$account = new Account();
$account->setAccountIdentifier($identifier);
$account->setCredentialsSource($this->hashService->hashPassword($password, $passwordHashingStrategy));
$account->setAuthenticationProviderName($authenticationProviderName);
$roles = [];
foreach ($roleIdentifiers as $roleIdentifier) {
$roles[] = $this->policyService->getRole($roleIdentifier);
}
$account->setRoles($roles);
return $account;
}
public function setUp() { parent::setUp(); $this->persistedUsernamePasswordProvider = new PersistedUsernamePasswordProvider('myTestProvider'); $this->accountFactory = new Security\AccountFactory(); $this->accountRepository = new Security\AccountRepository(); $this->authenticationToken = $this->getAccessibleMock(Security\Authentication\Token\UsernamePassword::class, array('dummy')); $account = $this->accountFactory->createAccountWithPassword('username', 'password', array(), 'myTestProvider'); $this->accountRepository->add($account); $this->persistenceManager->persistAll(); }