scouserider
scouserider

Reputation: 859

.net create membership without username

probabaly a daft question but when creating a user using .net membership, can i exclude the username and just have the email as the 'username' like this?

Membership.CreateUser(model.UserName, model.Password, model.Email, ....

or leave blank...

Membership.CreateUser("", model.Password, model.Email, ......

cheers

Upvotes: 1

Views: 581

Answers (2)

Malevolence
Malevolence

Reputation: 1857

What I have done in this case is generate a random username upon account creation. Then, when it comes time to log them in, call Membership.GetUserNameByEmail(emailAddress) to get the username and use that to log them in.

I didn't want to put the email address into the username field due to users occasionally changing their email addresses.

Upvotes: 2

Sam Holder
Sam Holder

Reputation: 32936

if you want the email as the username why not:

Membership.CreateUser(model.Email, model.Password, model.Email, ....

I'm not sure if an empty string for the username will be allowed (try it and see?) the docs are not clear, but as the docs state that a reason for failure can be MembershipCreateStatus.DuplicateUserName, you may only be allowed a single user with a blank name anyway...

Upvotes: 3

Related Questions