title: How to log in my custom user table in MVC 4?
body: <p>I want to use my custom <strong>User</strong> table in MVC 4 code first application. I defined advance <strong>User</strong> table in my database context:</p>
  
  <pre><code>public class MyDatabase : DbContext
      {
         public DbSet&lt;User&gt; UserSet { get; set; }
         public DbSet&lt;News&gt; NewsSet { get; set; }
         ...
      }
  </code></pre>
  
  <p>Model is like:</p>
  
  <pre><code> public class User 
      {
          [Key]
          public int Id{ get; set; }
          public string UserName { get; set; }
          public string Password { get; set; }
          public string Name { get; set; }
          public string SurName { get; set; }
          ...
      }
  </code></pre>
  
  <p>When application start, it calls this:</p>
  
  <pre><code>WebSecurity.InitializeDatabaseConnection("MyDatabase", "Users", "Id", "UserName", autoCreateTables: true);
  </code></pre>
  
  <p>In controller I use <strong>Add(entity)</strong> to save user entity. After saving I want to log in user. But it does not work:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Register(User user)
      {
       var result =  MyService.SaveUser(user);
       WebSecurity.Login(result.UserName, result.Password, true);
       return RedirectToAction("Index", "Profile", new { id = result.Id });
      }
  </code></pre>
  
  <p>After saving user, it's data stored in my database, but it can not log in. How should I do? </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Is it right to save User entity with my business method? Or I must do it only with 
  WebSecurity.CreateUserAndAccount()?</p>
  
  <p>If I can use my own save method, how to save password in database?</p>