Mike Cole
Mike Cole

Reputation: 14713

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.

Upvotes: 4

Views: 1304

Answers (1)

Kevin Junghans
Kevin Junghans

Reputation: 17540

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.

Upvotes: 8

Related Questions