Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming your table is called <code>AppUser</code>, convert your own <code>AppUser</code> domain object to <code>IUser(using Microsoft.AspNet.Identity)</code> like this</p> <pre><code>using Microsoft.AspNet.Identity; public class AppUser : IUser { //Existing database fields public long AppUserId { get; set; } public string AppUserName { get; set; } public string AppPassword { get; set; } public AppUser() { this.Id = Guid.NewGuid().ToString(); } [Ignore] public virtual string Id { get; set; } [Ignore] public string UserName { get { return AppUserName; } set { AppUserName = value; } } } </code></pre> <p>Implement the <code>UserStore</code> object like this</p> <pre><code>using Microsoft.AspNet.Identity; public class UserStoreService : IUserStore&lt;AppUser&gt;, IUserPasswordStore&lt;AppUser&gt; { CompanyDbContext context = new CompanyDbContext(); public Task CreateAsync(AppUser user) { throw new NotImplementedException(); } public Task DeleteAsync(AppUser user) { throw new NotImplementedException(); } public Task&lt;AppUser&gt; FindByIdAsync(string userId) { throw new NotImplementedException(); } public Task&lt;AppUser&gt; FindByNameAsync(string userName) { Task&lt;AppUser&gt; task = context.AppUsers.Where( apu =&gt; apu.AppUserName == userName) .FirstOrDefaultAsync(); return task; } public Task UpdateAsync(AppUser user) { throw new NotImplementedException(); } public void Dispose() { context.Dispose(); } public Task&lt;string&gt; GetPasswordHashAsync(AppUser user) { if (user == null) { throw new ArgumentNullException("user"); } return Task.FromResult(user.AppPassword); } public Task&lt;bool&gt; HasPasswordAsync(AppUser user) { return Task.FromResult(user.AppPassword != null); } public Task SetPasswordHashAsync(AppUser user, string passwordHash) { throw new NotImplementedException(); } } </code></pre> <p>If you have your own custom password hashing you will also need to implement <code>IPasswordHasher</code>. Below is an example where there is no hashing of the password(Oh no!)</p> <pre><code>using Microsoft.AspNet.Identity; public class MyPasswordHasher : IPasswordHasher { public string HashPassword(string password) { return password; } public PasswordVerificationResult VerifyHashedPassword (string hashedPassword, string providedPassword) { if (hashedPassword == HashPassword(providedPassword)) return PasswordVerificationResult.Success; else return PasswordVerificationResult.Failed; } } </code></pre> <p>In Startup.Auth.cs replace </p> <pre><code>UserManagerFactory = () =&gt; new UserManager&lt;IdentityUser&gt;(new UserStore&lt;IdentityUser&gt;()); </code></pre> <p>with </p> <pre><code> UserManagerFactory = () =&gt; new UserManager&lt;AppUser&gt;(new UserStoreService()) { PasswordHasher = new MyPasswordHasher() }; </code></pre> <p>In <code>ApplicationOAuthProvider.cs</code>, replace <code>IdentityUser</code> with <code>AppUser</code></p> <p>In <code>AccountController.cs</code>, replace <code>IdentityUser</code> with <code>AppUser</code> and delete all the external authentication methods like <code>GetManageInfo</code> and <code>RegisterExternal</code> etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload