public function registerAuthenticationRecord(User $user, string $username, string $password): AuthenticationRecordInterface
    {
        if (!$user->getId()) {
            throw new PersistedUserRequiredException("Your user must have an ID before you can create auth records with it");
        }

        if ($this->authenticationProvider->findByUsername($username)) {
            throw new UsernameTakenException();
        }

        if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
            if ($user->getEmail() !== $username) {
                throw new MismatchedEmailsException();
            }

            if ($emailUser = $this->userProvider->findByEmail($username)) {
                if ($emailUser !== $user) {
                    throw new EmailUsernameTakenException();
                }
            }
        }

        $hash = password_hash($password, PASSWORD_DEFAULT);
        $auth = $this->authenticationProvider->create(
            $user->getId(),
            $username,
            $hash,
            KeyFactory::generateEncryptionKey()->getRawKeyMaterial()
        );
        $this->authenticationProvider->save($auth);

        return $auth;
    }
public function registerAuthenticationRecord(User $user, string $username, string $password): AuthenticationRecordInterface
    {
        if (!$user->getId()) {
            throw new PersistedUserRequiredException("Your user must have an ID before you can create auth records with it");
        }

        if ($this->authenticationProvider->findByUsername($username)) {
            throw new UsernameTakenException();
        }

        if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
            if ($user->getEmail() !== $username) {
                throw new MismatchedEmailsException();
            }

            if ($emailUser = $this->userProvider->findByEmail($username)) {
                if ($emailUser !== $user) {
                    throw new EmailUsernameTakenException();
                }
            }
        }

        $hash = password_hash($password, PASSWORD_DEFAULT);
        $auth = $this->authenticationProvider->create(
            $user->getId(),
            $username,
            $hash,
            KeyFactory::generateEncryptionKey()->getRawKeyMaterial()
        );
        $this->authenticationProvider->save($auth);

        return $auth;
    }
public function registerAuthenticationRecord ( User $ user , string $ username , string $ password ) : AuthenticationRecordInterface { if ( ! $ user -> getId ( ) ) { throw new PersistedUserRequiredException ( "Your user must have an ID before you can create auth records with it" ) ; } if ( $ this -> authenticationProvider -> findByUsername ( $ username ) ) { throw new UsernameTakenException ( ) ; } if ( filter_var ( $ username , FILTER_VALIDATE_EMAIL ) ) { if ( $ user -> getEmail ( ) !== $ username ) { throw new MismatchedEmailsException ( ) ; } if ( $ emailUser = $ this -> userProvider -> findByEmail ( $ username ) ) { if ( $ emailUser !== $ user ) { throw new EmailUsernameTakenException ( ) ; } } } $ hash = password_hash ( $ password , PASSWORD_DEFAULT ) ; $ auth = $ this -> authenticationProvider -> create ( $ user -> getId ( ) , $ username , $ hash , KeyFactory :: generateEncryptionKey ( ) -> getRawKeyMaterial ( ) ) ; $ this -> authenticationProvider -> save ( $ auth ) ; return $ auth ; }
Very similar to create, except that it won't log the user in.  This was created to satisfy circumstances where
you are creating users from an admin panel for example.  This function is also used by create.

@param User   $user
@param string $username
@param string $password

@return AuthenticationRecordInterface
@throws EmailUsernameTakenException
@throws MismatchedEmailsException
@throws PersistedUserRequiredException
@throws UsernameTakenException
Very similar to create except that it won t log the user in . This was created to satisfy circumstances where you are creating users from an admin panel for example . This function is also used by create .