Username and Email

Aug 8, 2014 at 7:35 AM
Edited Aug 8, 2014 at 8:16 AM

I am building a .net MVC5 with EF6 app and I have hit a bit of a problem in the early stages which is quite frustrating as it is slowing down my progress.

Basically, I have a 'Register' section where I am allowing users to register for an individual account. The fields they have are - Email, Username, Password, Password Confirmation.

Now, when the user is registered, I would like a way to be able to authenticate the user via Email and password only. The site only requires the username when looking at the activity stream or the user profile. e.g.{username}

Is there a way to enable email and password authentication without having to hack at the core code.

I appreciate any advice or guidance.

Thank you in advance.

Aug 10, 2014 at 12:46 PM
I am making an assumption that you are writing code based on the 2013 template. You control the registration view, correct? Could you make the username field hidden, and set it to be the email address behind the scenes?
Aug 11, 2014 at 8:52 PM

Thank you for the reply.

I am not using the 2013 template as I prefer to start with an empty solution and build up the application at a steady pace only including what I require.

As such, I am using the identity features however, rolling my own implementation taking into account the repository pattern and other useful architectures.

Anyways - I had a good google around and found a great article which explains exactly how to do what I wanted which was the following:
  • Users will register with username, email and password and they will store in the relevant fields in Identity users table.
  • Users can authenticate with either the username/password combo, or the email/password combo.
  • This will automatically be detected during the postback and the correct c# methods will be run depending on the input.
  • In order to do this, I have to create an extended method (based on UserManager.FindAsync(model.UserName, model.Password);) which will do the exact same thing except do a look up on email rather than username
This is the article in case any else would like to implement a similar feature.

Sep 6, 2014 at 3:13 PM
Edited Sep 8, 2014 at 3:45 PM
(comment removed)