Before You dive further please go through these blogpost for more clarity and brevity.
- No Entity Framework.
- No Asp.net database tables
- Use existing Database user table for authentication.
1. IUser
2. IUserStore
3. UserManager
In order to refer our own table we have extended the method FindSync of UserManager.
public class CustomUserManager:UserManager<ApplicationUser>
{
public CustomUserManager() : base(new CustomUserSore<ApplicationUser>())
{
//We can retrieve Old System Hash Password and can encypt or decrypt old password using custom approach.
this.PasswordHasher = new OldSystemPasswordHasher();
}
public override System.Threading.Tasks.Task<ApplicationUser> FindAsync(string userName, string password)
{
Task<ApplicationUser> taskInvoke = Task<ApplicationUser>.Factory.StartNew(() =>
{
//First Verify Password...
PasswordVerificationResult result = this.PasswordHasher.VerifyHashedPassword(userName, password);
if (result == PasswordVerificationResult.SuccessRehashNeeded)
{
//Return User Profile Object...
//So this data object will come from DB via Nhiberanate
ApplicationUser applicationUser = new ApplicationUser();
applicationUser.UserName =
"san";
return applicationUser;
}
return null;
});
return taskInvoke;
}
}
For Source code
http://code.msdn.microsoft.com/Simple-Aspnet-Identiy-Core-7475a961
No comments :
Post a Comment