Ejemplo n.º 1
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));
        }