Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validating user in SimpleMembership

What is the alternative to Membership.ValidateUser() in SimpleMembership? I use WebSecurity.Login to validate the current user, but I have a situation where a user has to enter their password again to change some user settings. Should I just use WebSecurity.Login again? Seems like overkill.

like image 640
Mike Cole Avatar asked Feb 16 '23 06:02

Mike Cole


1 Answers

I also needed to just validate a user in SimpleMembership and I think I found a good solution. You just need to grab the membership provider and call the method from there. Here is how I did it.

public static bool ValidateUser(string userName, string password)
{
    var membership = (WebMatrix.WebData.SimpleMembershipProvider)Membership.Provider;
    return membership.ValidateUser(userName, password);
}

I created unit test for this and verified that it works. You can get a list of the methods available for this membership provider here.

I added this to the open source project SimpleSecurity, which looks at ways to extend SimpleMembership and provides examples on how to use SimpleMembership. It also decouples SimpleMembership from your MVC application.

like image 183
Kevin Junghans Avatar answered Mar 04 '23 08:03

Kevin Junghans