I’m working on a project where there are different three user types (Admin, Parent, and Teacher) that access the website. The users log in by providing their credentials and selecting their type as shown the image below

I wanted to provide a custom authentication and authorization for the users. By using the methods in this tutorial, I extended MemberShipProvider class for each user type and overrode the ValidateUser method and ended up with three classes named AdminAuthProvider, ParentAuthProvider and TeacherAuthProvider. Here is the code in the ValidateUser method in AdminAuthProvider
public override bool ValidateUser(string username, string password)
{
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
{
return false;
}
using (var db = new pscsEntities())
{
return db.Admins.Any(admin => admin.username.Equals(username) && admin.password.Equals(password));
}
}
The code for ValidateUser in the other two classes is the same.
My Questions are
- Is there a better way of doing the authentication in a single class rather than three classes which extend the same classes?
- How can I provide authorization roles in this scenario?
For the second question, the above tutorial suggests extending the RoleProvider class and overriding its methods. What I can’t seem to figure out how to override the GetRolesForUser method as it only takes a single string parameter which is the username of the currently logged in user. I’m a bit confused here.
If it helps here is the table diagrams for the three users in the database
