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 496969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:44:13+00:00 2026-05-13T05:44:13+00:00

Please help! I am new to the .NET web application development. I have used

  • 0

Please help!

I am new to the .NET web application development. I have used the code from the link below to create a basic login page in front of the Microsoft Live Single Sing On.

http://support.microsoft.com/default.aspx/kb/326340

I managed to combine the two together (LiveSSO w/ Forms Authentication) turning off the Integrated Authentication in IIS from the SSO setup. All works as expected if the user successfully authenticates with AD.

THE PROBLEM that I am having is that when the user failes to authenticate it only returns: “Error authenticating user. Logon failure: unknown user name or bad password”. This message appears also when the user is set to change the password at next logon. What I want it to do is to read the error code of exactly why it failed so I can setup a redirect to a password reset page (i.e. if error is “User flag is set to change pswd” etc.etc.)

From the page linked above you can see the VB code of LdapAuthentication.vb which does the trick of authenticating the accounts or returning the error message if the login fails.

The part that returns the “Error authenticating user. Logon failure: unknown user name or bad password.” Is handled by this subroutine:

  1. Catch ex As Exception
  2. Throw New Exception(“Error authenticating user. ” & ex.Message)
  3. End Try

That’s what I have been trying to customize to see how it can return a specific code based on the user account AD flags, instead of the generic message.

Does anyone have any clue or idea how I can accomplish that? Any help would be greatly appreciated. Thanks in advance!

  • 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-13T05:44:13+00:00Added an answer on May 13, 2026 at 5:44 am

    I’m pretty sure you are already seeing the most detailed error that AD is going to throw at you given the technique being used.

    When a login fails, AD is deliberately a little vague as to the exact reason. This prevents hackers from knowing which part of the login credentials they may have gotten right or wrong, thus denying them the ability to tailor their next attempt based on information gleaned from their earlier failures.

    To do what you are wanting to do, you will need to have different code that connects to AD using a service account setup for the application. This code would then need to take the credentials the user supplied, find the relevant directory entry for that user, then read the information about the account reset flags and such.

    Once that’s done, and everything is OK, you’d then pass control off the the actual login code and attempt the login for the user. If everything weren’t OK, you’d redirect the user without attempting to log them in with their own credentials.

    [Update]

    Here is a quick code example of how you “might” go about doing something like this:

    Public Function DoesUserHaveToChangePassword(ByVal userName As String) As Boolean
    
        Dim ctx As var = New PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain)
        Dim up As var = UserPrincipal.FindByIdentity(ctx, userName)
        Return (Not up.LastPasswordSet.HasValue AndAlso Not up.PasswordNeverExpires)
        'returns true if last password set has no value and the password never expires option is not set.
    
    End Function
    

    VB is not my native language of choice, so this is an untested conversion from a quick example I mocked up in C#. No guarantees that this will work exactly as is.

    You will need to import the System.DirectoryServices.AccountManagement namespace to use this.

    The PrincipalContext constructor shown in this example is the very basic version, and will only work if your web application itself is using a service account that has the necessary access to your active directory to read from it. If not, look at the overloads for the constructor and use the one that lets you supply the domain user and password credentials used to build the PrincipalContext.

    The major point of the function here is to check the LastPasswordSet value AND the PasswordNeverExpires value from AD for the user account that is about to attempt a login. If both of these are unset, then the user’s account will require them to change the password before they login.

    So you’d just make a call to this function BEFORE you try authenticating the user. If the function returns true then the user cannot login until they change the password and you should redirect the user to a change password page.

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

Sidebar

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.