Ejemplo n.º 1
0
        public async Task <bool> VerifyOneTimePassword(User user, OnePasswordType kind, string code)
        {
            Generator = NewGenerator(user);

            // TODO: Stop Storing One Time Passwords, maybe just count them?
            OneTimePassword password = user.OneTimePasswords.
                                       FirstOrDefault(p => p.IsActive && p.Kind == kind);

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

            if (!Generator.VerifyHotp(code, user.OneTimePasswords.LongCount()))
            {
                return(false);
            }

            return(await Task.FromResult(password.Code == code));
        }
Ejemplo n.º 2
0
        public async Task <bool> ValidateOneTimePassword(User user, OnePasswordType kind, string code)
        {
            Generator = NewGenerator(user);

            // TODO: Stop Storing One Time Passwords, maybe just count them?
            OneTimePassword password = user.OneTimePasswords.
                                       FirstOrDefault(p => p.IsActive && p.Kind == kind);

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

            if (!Generator.VerifyHotp(code, user.OneTimePasswords.LongCount()))
            {
                return(false);
            }
            if (!password.Validate(code))
            {
                return(false);
            }

            switch (kind)
            {
            // TODO: Deprecate OnePasswordType
            case OnePasswordType.Email:
                user.EmailConfirmed = true;
                break;

            case OnePasswordType.Phone:
                user.PhoneNumberConfirmed = true;
                break;
            }

            await DataStore.UpdateOneAsync(user);

            return(true);
        }
Ejemplo n.º 3
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);
        }