Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return more detailed error when user cannot be validated

I am working on creating a custom membership class for my asp.net project. In the MembershipProvider class, function for user validation is defined as follows.

public abstract bool ValidateUser(string username, string password);

The problem is validation can be failed for several reason, so I want to provide more detailed description as to why login failed (e.g., user is lockedout etc) but that cannnot be done via a bool return type. I certainly can create one of my method for validation as follows

public RichStatusDetailsEnum ValidateUser(string username, string password);

Problem with above is that I will not be able to call this method in a generic way (just by Membership.ValidateUser). Rather I will have to instantiate object of my custom membership provider etc etc. Does anyone else has encountered same issue and if there are any better ways of handling this type of situation?

like image 572
palm snow Avatar asked Feb 03 '26 08:02

palm snow


1 Answers

As per this MSDN resource, the return will tell you if it is valid. There are only two parameters (username and password). If it is a false return, then you know one of them is off. You can always test if the UserName is correct by calling Membership.GetUser(). If the MembershipUser object returned is not null, then you know the UserName is correct. In which case, that would lead you to believe that if ValidateUser() fails, it is a bad password.

To see if the user is locked out: for the MembershipUser object that gets returned from GetUser(), you can test if the user is locked out by the property Membershipuser.IsLockedOut.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!