コード例 #1
0
        public async Task<CreateLocalAccountResult> CreateAsync(Guid identityId, string loginId, string password)
        {
            var bytes = new byte[_options.NumberOfBytesInPasswordSalt];
            CryptoRandom.GetBytes(bytes);

            var localAccount = new LocalAccount
            {
                IdentityId = identityId,
                IterationCount = _options.IterationCount,
                PasswordSalt = bytes,
                LoginId = loginId,
                Created = DateTimeOffset.Now,
                Updated = DateTimeOffset.Now
            };

            localAccount.PasswordHash = GetPasswordHash(password, localAccount);

            try
            {
                await _localAccountStorage.CreateAsync(localAccount);
            }
            catch (IdentityAlreadyExistException e)
            {
                _log.LogError(0, e, "Local account already exist");

                return CreateLocalAccountResult.AlreadyExist();
            }

            return CreateLocalAccountResult.Success(localAccount);
        }
コード例 #2
0
        public async Task <CreateLocalAccountResult> CreateAsync(Guid identityId, string loginId, string password)
        {
            var passwordSalt = new byte[_options.NumberOfBytesInPasswordSalt];
            var totpSecret   = new byte[64];

            CryptoRandom.GetBytes(passwordSalt);
            CryptoRandom.GetBytes(totpSecret);

            var localAccount = new LocalAccount
            {
                IdentityId       = identityId,
                IterationCount   = _options.IterationCount,
                PasswordSalt     = passwordSalt,
                SharedTotpSecret = totpSecret,
                LoginId          = loginId
            };

            localAccount.PasswordHash = GetPasswordHash(password, localAccount);

            try
            {
                await _localAccountStorage.CreateAsync(localAccount);
            }
            catch (IdentityAlreadyExistException e)
            {
                _log.LogError(0, e, "Local account already exist");

                return(CreateLocalAccountResult.AlreadyExist());
            }

            return(CreateLocalAccountResult.Success(localAccount));
        }