title: How to save new record with hashed password in my custom table instead of aspnet user?
body: <p>I am using asp.net identity to create new user but getting error:</p>
  
  <blockquote>
    <p>Cannot insert the value NULL into column 'Id', table
    'Mydb.dbo.AspNetUsers'; column does not allow nulls. INSERT
    fails.\r\nThe statement has been terminated</p>
  </blockquote>
  
  <p>But here I don't have any such table like <strong>AspNetUsers</strong> but instead I have my own table that is <strong>Users</strong>.</p>
  
  <p><strong>Code:</strong>
  <strong>Web.config: 2 conection strings</strong></p>
  
  <pre><code> &lt;add name="myEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;data source=;initial catalog=mydb;user id=sa;password=sdfsdfsdf;MultipleActiveResultSets=True;App=EntityFramework&amp;quot;" providerName="System.Data.EntityClient" /&gt;
   &lt;add name="MyConnString" connectionString="data source=;initial catalog=Mydb;user id=sa;password=sdfsdfsdf;" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p><strong>IdentityModel.cs:</strong></p>
  
  <pre><code>public class ApplicationUser : IdentityUser
      {
          public async Task&lt;ClaimsIdentity&gt; GenerateUserIdentityAsync(UserManager&lt;ApplicationUser&gt; manager)
          {
              // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
              this.SecurityStamp = Guid.NewGuid().ToString();
              var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
              // Add custom user claims here
              return userIdentity;
          }
  
          public string Id { get; set; }
          public string FirstName { get; set; }
          public string LastName { get; set; }
          public virtual string Email { get; set; }
          public string Password { get; set; }
          public string Role { get; set; }
          public Nullable&lt;bool&gt; IsActive { get; set; }
          public Nullable&lt;int&gt; CreatedBy { get; set; }
          public Nullable&lt;System.DateTime&gt; CreatedDate { get; set; }
          public Nullable&lt;System.DateTime&gt; LastLogin { get; set; }
  
          public ApplicationUser()
          {
  
          }
  
          public ApplicationUser(string email, string firstName, string lastName, string designation, bool isActive)
          {
              Email = email;
              FirstName = firstName;
              LastName = lastName;
              Designation = designation;
              IsActive = isActive;
          }
      }
    public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
      {
          public ApplicationDbContext()
              : base("MyConnString", throwIfV1Schema: false)
          {
          }
  
          public static ApplicationDbContext Create()
          {
              return new ApplicationDbContext();
          }
      }
  </code></pre>
  
  <p><strong>UserStore1.cs:</strong></p>
  
  <pre><code>public class UserStore1 : IUserStore&lt;ApplicationUser&gt;, IUserPasswordStore&lt;ApplicationUser&gt;
      {
          private readonly HttpContext _httpContext;
          UserStore&lt;IdentityUser&gt; userStore = new UserStore&lt;IdentityUser&gt;(new ApplicationDbContext());
  
          public System.Threading.Tasks.Task CreateAsync(ApplicationUser user)
          {
              HttpContext.Current = _httpContext ?? HttpContext.Current;
              var context = userStore.Context as ApplicationDbContext;
             context.Users.Add(user);
             context.Configuration.ValidateOnSaveEnabled = false;
             context.SaveChanges();
              return Task.FromResult(true);
          }
       }
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>     [Authorize]
      public class AccountController : Controller
      {
          public AccountController()
              : this(new UserManager&lt;ApplicationUser&gt;(new UserStore1()))
          {
          }
  
          public AccountController(UserManager&lt;ApplicationUser&gt; userManager)
          {
              UserManager = userManager;
          }
          public UserManager&lt;ApplicationUser&gt; UserManager { get; private set; }
  [HttpPost]
          [AllowAnonymous]
          [ValidateAntiForgeryToken]
          public async Task&lt;ActionResult&gt; Login(string email, string password, bool rememberMe = false, string returnUrl = null)
          {
              if (ModelState.IsValid)
              {
                  var user = new ApplicationUser
                  {
                      FirstName= "Abc",
                      LastName= "Pqr",
                      UserName="Abc@yahoo.com",
                      SecurityStamp = Guid.NewGuid().ToString()
                  };
  
                  var result= await UserManager.CreateAsync(user,"123456");
              }
              return View();
          }
      }
  </code></pre>
  
  <p>Note: I have autogenerated Id in my database table field and that Id is Int.</p>
  
  <p>Update: I am using database first(edmx) and the table that I am using are custom tables for inserting new records(for eg:<strong>Users</strong>).</p>
  
  <p>At first I have implemented microsoft asp.net identity as shown in below question but 1 user pointed out that I am not using <strong>ApplicationUser class</strong> which is responsible for handling <strong>sign in,cookies</strong> etc so I am now trying to use <strong>ApplicationUser</strong> class:</p>
  
  <p><a href="https://stackoverflow.com/questions/39275597/how-to-give-custom-implementation-of-updateasync-method-of-asp-net-identity">How to give custom implementation of UpdateAsync method of asp.net identity?</a></p>
  
  <p>I am really now regretting over my decision to choose Microsoft Identity Framework for Authentication purpose as because I am really finding it complex but now as I have move forward I have to go with it.</p>