Beispiel #1
0
        /// <summary>
        /// Gets an identity by its unique user-chosen identifier.
        /// </summary>
        /// <param name="identifier">The identifier of the identity to retrieve.</param>
        /// <returns>Returns the identity, if found.</returns>
        /// <exception cref="EntityNotFoundException">Thrown if the identity could not be found.</exception>
        public async Task <Identity> GetIdentity(string identifier)
        {
            Identity identity = await IdentityRepository.GetIdentity(identifier);

            if (identity == null)
            {
                throw new EntityNotFoundException("Identity", identifier);
            }
            return(identity);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new identity.
        /// </summary>
        /// <param name="identifier">The unique user-chosen identifier with this identity.</param>
        /// <param name="password">The as-of-yet unhashed password of this identity.</param>
        /// <returns></returns>
        /// <exception cref="EntityAlreadyExsistsException">Identity</exception>
        public async Task <Identity> CreateIdentity(string identifier, string password)
        {
            // Validate identifier format and availability
            IdentifierValidationService.Validate(identifier);
            if ((await IdentityRepository.GetIdentity(identifier)) != null)
            {
                throw new EntityAlreadyExsistsException("Identity", identifier);
            }

            // Validate client-provided password
            PasswordValidationService.Validate(password);

            // Hash password and create new identity
            (string hash, byte[] salt) = PasswordHashingService.HashAndSaltPassword(password);
            return(await IdentityRepository.CreateIdentity(identifier, hash, salt));
        }