codeandcloud
codeandcloud

Reputation: 55200

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.

Upvotes: 5

Views: 5196

Answers (2)

user3452580
user3452580

Reputation: 35

There is a method in JQuery Form.validate you can use it for this pupose

here you can see the code

 $(document).ready(function () {
 $("#formData").validate({
            rules: {
                fname: {
                    minLength: 3,
                    required: true,
                    remote: { url: "UserAccount/Register", type: post }
                },
            },
            messages : {
                minLength: "ATlesat 3 characters required for user name",
                required: "user name is required",
                remote : "User name already exist"
            } 
        });

    });

Upvotes: -2

Bebben
Bebben

Reputation: 735

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!

Upvotes: 10

Related Questions