Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5963651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:17:27+00:00 2026-05-22T19:17:27+00:00

I am working on an ASP.Net Mvc 3 application using FormsAuthentication with a custom

  • 0

I am working on an ASP.Net Mvc 3 application using FormsAuthentication with a custom MembershipProvider (so I do have some control over what the provider returns).

The requirements mandate a 2-step authentication process (username and password followed by secret question). A user should not be able to access any of the “secure” sections of the site without passing both steps. Please don’t mention whether this is multi-factor security or not, I already know.

Please provide a recommendation on how to best accomplish this task.

Here are some considerations:

  • I am allowed (architecturally) to use session – would prefer not to.
  • I would prefer to use the out-of the box [Authorize] ActionFilter for Controllers providing secure content.
  • The people in charge would like for the url for the 2 steps to be the same: i.e. www.contoso.com/login/. In my attempts at least, this has caused some minor-but-not-insignificant issues when users enter an incorrect answer in the second step (they are not officially logged in, but I need to ensure that I am still working against the half-authenticated user’s secret question/answer).

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:17:28+00:00Added an answer on May 22, 2026 at 7:17 pm

    Use a custom View Model in conjunction with hidden form fields. Just make sure it’s all done over https.

    ViewModel

    public LoginForm
    {
        public string UserName { get; set; }
        public string Password { get; set; }
    
        public int SecretQuestionId { get; set; }
        public string SecretQuestion { get; set; }
        public string SecretQuestionAnswer { get; set; }
    }
    

    Action Methods

    public ActionResult Login()
    {
        var form = new LoginForm();
        return View(form);
    }
    
    [HttpPost]
    public ActionResult Login(LoginForm form)
    {
        if (form.SecretQuestionId == 0)
        {
            //This means that they've posted the first half - Username and Password
            var user = AccountRepository.GetUser(form.UserName, form.Password);
            if (user != null)
            {
                //Get a new secret question
                var secretQuestion = AccountRepository.GetRandomSecretQuestion(user.Id);
                form.SecretQuestionId = secretQuestion.Id;
                form.SecretQuestion = secretQuestion.QuestionText;
            }
        }
        else
        {
            //This means that they've posted from the second half - Secret Question
            //Re-authenticate with the hidden field values
            var user = AccountRepository.GetUser(form.UserName, form.Password);
            if (user != null)
            {
                if (AccountService.CheckSecretQuestion(form.SecretQuestionId, form.SecretQuestionAnswer))
                {
                    //This means they should be authenticated and logged in
                    //Do a redirect here (after logging them in)
                }
            }
        }
    
        return View(form);
    } 
    

    View

    <form>
        @if (Model.SecretQuestionId == 0) {
            //Display input for @Model.UserName
            //Display input for @Model.Password
        }
        else {
            //Display hidden input for @Model.UserName
            //Display hidden input for @Model.Password
            //Display hidden input for @Model.SecretQuestionId
            //Display @Model.SecretQuestion as text
            //Display input for @Model.SecretQuestionAnswer
        }
    </form>
    

    If you’re not happy with sending the username and password back to the view in hidden fields to re-authenticate and make sure they’re not cheating… you could create a HMAC or something like that to test.

    Btw, this question seems like a few questions rolled into one… so just answered how to do 2-step authentication with one view / action method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a multi-tenant ASP.NET MVC application. So far we have been using
I have a asp.net mvc application and am trying to get custom errors working
I am working on asp.net mvc application using the mvc2 framework. Here is the
I am working on an ASP.NET MVC application and using jQuery. I understand from
I have an ASP.NET MVC application using Authorization Attributes on Controllers and Actions. This
I'm working on an application using ASP.NET MVC 1.0 and I'm trying to inject
I'm working on a Web project using Asp.Net MVC, which I'll have to deploy
As I am working on Asp.Net MVC Application, in my application I am using
I am busy working with an ASP.NET MVC 3 application and using Windows 7.
I'm working on an asp.net MVC 3 application which is using Data Models from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.