Search code examples
c#asp.netasp.net-membershipforms-authentication

Best method to check if username already exist in forms authentication


I have the username entered from a form Which method to use if that username is unique?

Membership.FindUsersByName or Membership.GetUser

Or any other methods?

I am asking this specifically because I didn't see a method returning bool as its common in checking unique values.


Solution

  • Membership.GetUser has slightly better performance. Also, Membership.FindUsersByName performes a LIKE statement if you are using SQL Membership, so it is not meant for unique names as you are trying to do.

    Short answer: to get best performance and find unique names, use Membership.GetUser!