title: Customising ApplicationUser asp.net-identity
body: <p>I'm trying to add a list of objects the the standard ApplicationUser object in MVC.</p>
  
  <p>I've been looking at dozens of questions all about this but they all seem to be adding a single object, rather than a list.</p>
  
  <p>What I'm trying to do is record all historic passwords a user has used, so I've added a table called <code>AspNetUserPreviousPassword</code>.</p>
  
  <p>In my code I've added this line to the <code>ApplicationUser</code>class:</p>
  
  <pre><code>public virtual DbSet&lt;AspNetUserPreviousPassword&gt; PreviousUserPasswords { get; set; }
  </code></pre>
  
  <p>and within the <code>AspNetUserPreviousPassword</code> object I've added the following:</p>
  
  <pre><code>public string ApplicationUserId { get; set; }
  public ApplicationUser ApplicationUser { get; set; }
  </code></pre>
  
  <p>I've created the following extensions class:</p>
  
  <p>public static class IdentityExtensions which has appeared in the <code>User.Identity</code> intellisense - so far so good.</p>
  
  <pre><code>{
      public static string GetPreviousUserPasswords(this IIdentity identity)
      {
          var claim = ((ClaimsIdentity)identity).FindFirst("PreviousUserPasswords");
          // Test for null to avoid issues during local testing
          return (claim != null) ? claim.Value : string.Empty;
      }
  }
  </code></pre>
  
  <p>When I went to edit the <code>GenerateUserIdentityAsync</code> function, to insert the custom claims, I began to think my approach was incorrect as you can only add strings, e.g.</p>
  
  <pre><code>userIdentity.AddClaim(new Claim("PreviousUserPasswords", "This must be a string"));
  </code></pre>
  
  <p>Despite only being able to add a string here, I wanted to test my previous passwords were being read from the database so I added this code to test:</p>
  
  <pre><code>string previousPasswords = "";
  await this.PreviousUserPasswords.ForEachAsync(p =&gt; previousPasswords += p.PasswordHash);
  </code></pre>
  
  <p><code>this.PreviousUserPasswords</code> is always <code>NULL</code>.</p>
  
  <p>My questions:</p>
  
  <p>1) Why is <code>this.PreviousUserPasswords</code> always <code>NULL</code>?</p>
  
  <p>2) Is my approach even correct - can I add a list of objects to <code>ApplicationUser</code> or should I be doing this another way?</p>