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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With