title: asp.net identity userName is unique?
body: <p>I was reading about user Identity in Microsoft and trying to apply them in my MVC5 app.</p>
  
  <p>Up to my knowledge the Id is the key, while the userName is not key and the definition says that it can be null,
  so I was asking myself... why in the MVC5 project template, when you enter an already existing userName you will receive an Error message ??</p>
  
  <p>I tried to reach to the userName validation but I couldn't.</p>
  
  <p>Here is  the database definition:</p>
  
  <pre><code>CREATE TABLE [dbo].[AspNetUsers] (
      [Id]            NVARCHAR (128) NOT NULL,
      [UserName]      NVARCHAR (MAX) NULL,
  </code></pre>
  
  <p>and here is the IdentityUser definition, notice (no validation):</p>
  
  <pre><code>namespace Microsoft.AspNet.Identity.EntityFramework
  {
      public class IdentityUser : IUser
      {
          public IdentityUser();
          public IdentityUser(string userName);
  
          public virtual ICollection&lt;IdentityUserClaim&gt; Claims { get; }
          public virtual string Id { get; set; }
          public virtual ICollection&lt;IdentityUserLogin&gt; Logins { get; }
          public virtual string PasswordHash { get; set; }
          public virtual ICollection&lt;IdentityUserRole&gt; Roles { get; }
          public virtual string SecurityStamp { get; set; }
          public virtual string UserName { get; set; }
      }
  }
  </code></pre>
  
  <p>and on registration, the <code>UserManager.CreateAsync</code> method is called, here is the definition:</p>
  
  <pre><code>     public async Task&lt;ActionResult&gt; Register(RegisterViewModel model)
          {
              if (ModelState.IsValid)
              {
                  var user = new ApplicationUser() { UserName = model.UserName };
                  var result = await UserManager.CreateAsync(user, model.Password);
                  if (result.Succeeded)
                  {
                      await SignInAsync(user, isPersistent: false);
                      return RedirectToAction("Index", "Home");
                  }
                  else
                  {
                      AddErrors(result);
                  }
              }
  
              // If we got this far, something failed, redisplay form
              return View(model);
          }
  </code></pre>
  
  <p>and this is the last thing I reach regarding <code>CreateAsync</code>:</p>
  
  <pre><code>public virtual Task&lt;IdentityResult&gt; CreateAsync(TUser user, string password);
  </code></pre>
  
  <p>I don't see validation anywhere in the code, however it won't allow you to enter an existing userName.</p>
  
  <p>I think understanding how does this works will improve my experience with the Identity concept of asp.net and will improve my code.</p>
  
  <p>Any guidance is highly appreciated </p>