예제 #1
0
        public async Task <OneTimePassword> GenerateOneTimePassword(User user, OnePasswordType kind)
        {
            Generator = NewGenerator(user);

            OneTimePassword password = user.OneTimePasswords
                                       .FirstOrDefault(p => p.IsActive && p.Kind == kind);

            if (password != null)
            {
                return(password);
            }

            password = new OneTimePassword()
            {
                Kind = kind
            };

            user.OneTimePasswords.Add(password);

            password.Code = Generator.ComputeHOTP(user.OneTimePasswords.LongCount());
            await DataStore.UpdateOneAsync(user);

            return(password);
        }