title: Hashed Password with EF 4.1 Database first / ASP.NET MVC 3
body: <p>I'm rolling my own authentication system and I've run into a situation that I need guidance on.</p>
  
  <p>I'm <em>not</em> using EF 4.1 code first. I've designed my database to include a User table with an Id, Email and HashedPassword column. I then let EF create an entity based off this table. I then created a partial class to handle my validation.</p>
  
  <p>The problem is that within my view I want to have a textbox for email, password and confirm password. I need validation on password and confirm password (required and compare). I can add these to the validation class I created but because they aren't part of the entity EF created for the User table, I get compiler errors when I try to view the page.</p>
  
  <p>My partial class</p>
  
  <pre><code>[MetadataType(typeof (UserMetadata))]
      public partial class User
      {
          private class UserMetadata
          {
              [Required]
              public string Email { get; set; }
  
              [Required]
              public string Password { get; set; }
  
              [Required]
              [Compare("Password")]
              public string ConfirmPassword { get; set; }
          }
      }
  </code></pre>
  
  <p>My view</p>
  
  <pre><code>&lt;h1&gt;Sign Up&lt;/h1&gt;
  @using (Html.BeginForm("Create", "Users", FormMethod.Post))
  {
      @Html.ValidationSummary()
      &lt;p&gt;
          @Html.LabelFor(x =&gt; x.Email)&lt;br /&gt;
          @Html.TextBoxFor(x =&gt; x.Email)
      &lt;/p&gt;
       &lt;p&gt;
          @Html.LabelFor(x =&gt; x.Password)&lt;br /&gt;
          @Html.TextBoxFor(x =&gt; x.Password)
      &lt;/p&gt;
      &lt;p&gt;
          @Html.LabelFor(x =&gt; x.ConfirmPassword)&lt;br /&gt;
          @Html.TextBoxFor(x =&gt; x.ConfirmPassword)
      &lt;/p&gt;
  
      &lt;p class="button"&gt;
          &lt;input type="submit" value="Submit" /&gt;&lt;/p&gt;
  }
  </code></pre>
  
  <p>My model</p>
  
  <p>Table Name: Users
  Columns: Id, Email, HashedPassword</p>
  
  <p>How can I get around this?</p>
  
  <p>Thanks</p>