, AppUser, AppUser IUser ( Microsoft.AspNet.Identity),
using Microsoft.AspNet.Identity;
public class AppUser : IUser
{
public long AppUserId { get; set; }
public long 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; }
}
}
UserStore, ( FindByNameAsync . db)
using Microsoft.AspNet.Identity;
public class UserStoreService :
IUserStore<AppUser>, IUserPasswordStore<AppUser>,
IUserSecurityStampStore<AppUser>
{
CompanyDbContext context = new CompanyDbContext();
public Task CreateAsync(AppUser user)
{
throw new NotImplementedException();
}
public Task DeleteAsync(AppUser user)
{
throw new NotImplementedException();
}
public Task<AppUser> FindByIdAsync(string userId)
{
throw new NotImplementedException();
}
public Task<AppUser> FindByNameAsync(string userName)
{
Task<AppUser> task =
context.AppUsers.Where(apu => apu.AppUserName == userName)
.FirstOrDefaultAsync();
return task;
}
public Task UpdateAsync(AppUser user)
{
throw new NotImplementedException();
}
public void Dispose()
{
context.Dispose();
}
public Task<string> GetPasswordHashAsync(AppUser user)
{
if (user == null)
{
throw new ArgumentNullException("user");
}
return Task.FromResult(user.AppPassword);
}
public Task<bool> HasPasswordAsync(AppUser user)
{
return Task.FromResult(user.AppPassword != null);
}
public Task SetPasswordHashAsync(AppUser user, string passwordHash)
{
throw new NotImplementedException();
}
public Task<string> GetSecurityStampAsync(AppUser user)
{
throw new NotImplementedException();
}
public Task SetSecurityStampAsync(AppUser user, string stamp)
{
throw new NotImplementedException();
}
}
, IPasswordHasher. (!)
using Microsoft.AspNet.Identity;
public class PasswordHasher : 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;
}
}
Startup.Auth.cs
UserManagerFactory = () =>
new UserManager<IdentityUser>(new UserStore<IdentityUser>());
var userManager = new UserManager<AppUser>(new UserStoreService());
userManager.PasswordHasher = new PasswordHasher();
UserManagerFactory = () => userManager;
ApplicationOAuthProvider.cs IdentityUser AppUser. AccountController.cs IdentityUser AppUser , GetManageInfo RegisterExternal ..