public async Task <ActionResponse> AuthenticateCodeAsyc(AuthenticateInputModel model)
        {
            model.OneTimeCode = model.OneTimeCode.Replace(" ", "");
            var response = await _oneTimeCodeService.CheckOneTimeCodeAsync(model.Username, model.OneTimeCode);

            switch (response.Result)
            {
            case CheckOneTimeCodeResult.Verified:
                var user = await _userStore.GetUserByEmailAsync(model.Username);     //todo: handle non-email addresses

                if (user != null)
                {
                    return(Redirect(ValidatedNextUrl(response.RedirectUrl)));
                }
                return(Unauthenticated("Invalid one time code"));

            case CheckOneTimeCodeResult.Expired:
                return(Unauthenticated("Your one time code has expired. Please request a new one."));

            case CheckOneTimeCodeResult.CodeIncorrect:
            case CheckOneTimeCodeResult.NotFound:
                return(Unauthenticated("Invalid one time code"));

            case CheckOneTimeCodeResult.ShortCodeLocked:
                return(Unauthenticated("The one time code is locked. Please request a new one after a few minutes."));

            case CheckOneTimeCodeResult.ServiceFailure:
            default:
                return(ServerError("Something went wrong."));
            }
        }
        public async Task <ActionResponse> AuthenticateAsync(AuthenticatePasswordInputModel model)
        {
            var oneTimeCode = model.Password.Replace(" ", "");

            if (oneTimeCode.Length == 6 && oneTimeCode.All(Char.IsDigit))
            {
                var input = new AuthenticateInputModel()
                {
                    Username     = model.Username,
                    OneTimeCode  = oneTimeCode,
                    StaySignedIn = model.StaySignedIn
                };
                return(await AuthenticateCodeAsyc(input));
            }
            else
            {
                return(await AuthenticatePasswordAsync(model));
            }
        }