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

  • SEARCH
  • Home
  • 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 7556205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:48:28+00:00 2026-05-30T11:48:28+00:00

I have a MVC 3 app. There are mainly two zones regarding security. The

  • 0

I have a MVC 3 app. There are mainly two zones regarding security. The first one is mostly to prevent public access, but not really sensitive information. Password strength might be weak since there is not really much harm to do either.

Second zone(Area) is restricted. user must apply for access. If user gets access it gets a certain role(s). So each controller method autorizes the user based on that role.

I want these users to have to change password to a strong password on the next logon before they can go further and access the restricted content.

Example:

User A applies for access.
Access is granted. The password policy for
that user is changed as long as it has access. They MUST
change their password on the next logon, and they cannot change back
to a weaker password as long as they have that role.

Is there any secure way to implement this using the ASP.NET?

Update

I’ve actually used Chris proposed solution and it works, but to handle the verification of the password itself I actually got some inspiration from Micah’s proposed solution too. However, it turns out that overriding MembershipProvider.OnValidatingPassword does imply also having to implement 10 + abstract methods that I really do not need to solve this.

A better solution in my eyes was hooking on to the Membership.ValidatingPassword EVENT. I do this inn App_Start, then I implement my own password validation in the event handler and that solved my problem.

Just to share the solution with you i present it here, toghether with Chris solution this solved my problem and hopefully for someone else too:

    void App_Start()
    {
        //To do custom validation on certain passwords set new event handler
        Membership.ValidatingPassword += Membership_ValidatingPassword;
    }

private void Membership_ValidatingPassword(object sender, ValidatePasswordEventArgs e)
    {
        //If the user is a new user, we let registration happen without strong password
        if (e.IsNewUser) return;


        MembershipUser membershipUser = Membership.GetUser(e.UserName);
        Guid userId = Guid.Parse(membershipUser.ProviderUserKey.ToString());

        //First check if the pwd is strong enough to be flagged, if so we flag it
        //using regex to validate the password (20 char, 2 uppercase so on)
        if (MyValidationClass.IsStrongPassword(e.Password, 20, 2, 4, 1))
        {
            //if the user does not already have a flag we set one
            MyValidationClass.SetStrongPasswordFlag(userId);
        }
        else
        {
            //If the user needs strong pwd, we cancel the operation and throw exception
            if (MyValidationClass.NeedsStrongPassword(e.UserName))
            {
                e.FailureInformation =
                    new MembershipPasswordException("Password does not satisfy reqirements!");
                e.Cancel = true;
            }
            else
            {
                MyValidationClass.RemoveStrongPasswordFlag(userId);
            }
        }
    }
  • 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-30T11:48:30+00:00Added an answer on May 30, 2026 at 11:48 am

    You could write your own Authorize Attribute to accommodate both. You simply need to then use it on the relevant sections of your application:

    For example:

    public class HasChangedPasswordAttribute : AuthorizeAttribute
    {      
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            UserRepository repo = new UserRepository();
            var user = repo.GetCurrentUser();
            bool hasSecurelyChangedPassword = user.HasSecurelyChangedPassword;
            return hasSecurelyChangedPassword;
        }
    
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            filterContext.Result = new RedirectResult("/Account/ChangePassword");
        }
    }
    

    The above will check that the user has securely changed their password. If not it will redirect them to a new page in which to change their password. Once they change it, set the flag as changed.

    You can then use it like this:

    [HasChangedPassword]
    [Authorize(Roles="SuperRole")]
    public ActionResult MySecureAction()
    {
     ...
    }
    

    You could obviously integrate both of these attributes into one, but for the sake of showing the example they are seperated above.

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

Sidebar

Related Questions

I have an ASP MVC web app and on one of the pages there
Iam using .NET 3.5. I have asp.net mvc app. There is base controller: public
I have a ASP.NET MVC 3 app with a common scenario where there is
I have an MVC app that is basically one page with a bunch of
I have two separate applications, a c# MVC app and a CMS (Ektron) app.
I have a mvc 3 app that uses EF. In one function I need
I have an MVC app I'm writing. There will be the need for multiple
I have a very simple MVC app at this point: Controller: public class HomeController
I have a C#.Net web app and I am trying to access one of
I have a MVC app and using JQuery. I have anchor that I setup

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.