What is the purpose of Membership.ValidateUser()
Asked Answered
M

2

7

I've been learning about the MembershipProvider class and I thought that the Membership.ValidateUser() method was supposed to be used to to log a user in.

However, I just learned that there is a FormsAuthentication.Authenticate().

What is the purpose of ValidateUser() within Membership?

Monahan answered 23/8, 2012 at 15:59 Comment(0)
P
10

In short, there are times when you might want to simply validate that a user is who they say they are without needing to persist an authentication cookie for any length of time.

Premeditate answered 23/8, 2012 at 16:1 Comment(3)
So should I use the MembershipProvider.ValidateUser() within an override of FormsAuthentication.Authenticate() ?Monahan
@Coulton, the Authenticate() method will essentially do the same thing in this context, so it's not necessary to override. Using the ValidateUser() method would in theory allow you to choose your provider, if you had more than one. The Authenticate() method just uses the one configured in your web.config.Premeditate
I've just noticed here that it says Authenticate() is obsolete and The recommended alternative is to use the Membership APIs, such as Membership.ValidateUser. For more information, see http://go.microsoft.com/fwlink/?LinkId=252463.. So I should use Membership.ValidateUser() and do my forms authentication within that methodMonahan
K
1

It only check your data source (database) if the passed username and password exist in the database and match and returns true Check MSDN. If they don't match, it returns false

public static bool ValidateUser(string username, string password)
Kettie answered 23/8, 2012 at 16:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.