Class BasicAuthenticationService
Authentication service implementation that delegates to ICredentialRepository. Provides password hashing and verification utilities.
public class BasicAuthenticationService : IAuthenticationService
- Inheritance
-
BasicAuthenticationService
- Implements
- Inherited Members
Constructors
BasicAuthenticationService(ICredentialRepository, IPatientRepository, IPhysicianRepository, IAdministratorRepository)
Authentication service implementation that delegates to ICredentialRepository. Provides password hashing and verification utilities.
public BasicAuthenticationService(ICredentialRepository credentialRepository, IPatientRepository patientRepository, IPhysicianRepository physicianRepository, IAdministratorRepository administratorRepository)
Parameters
credentialRepositoryICredentialRepositorypatientRepositoryIPatientRepositoryphysicianRepositoryIPhysicianRepositoryadministratorRepositoryIAdministratorRepository
Methods
Authenticate(string, string)
Authenticates a user with username and password
public AuthenticationResult Authenticate(string username, string password)
Parameters
Returns
- AuthenticationResult
Authentication result with profile on success, or failure reason
ChangePassword(string, string, string)
Changes a user's password
public bool ChangePassword(string username, string currentPassword, string newPassword)
Parameters
usernamestringThe username whose password to change
currentPasswordstringThe current password for verification
newPasswordstringThe new password to set
Returns
- bool
True if password change successful, false otherwise
GetAllUsernames()
Gets all registered usernames (for debugging/testing only)
public IEnumerable<string> GetAllUsernames()
Returns
GetLastLoginTime(string)
Gets the last login time for a user
public DateTime? GetLastLoginTime(string username)
Parameters
usernamestringThe username to check
Returns
- DateTime?
The last login DateTime, or null if never logged in
HashPassword(string)
Simple password hashing for Assignment 1. Production would use BCrypt, Argon2, or similar.
public static string HashPassword(string password)
Parameters
passwordstring
Returns
Register(IUserProfile, string)
Registers a new user in the system
public bool Register(IUserProfile profile, string password)
Parameters
profileIUserProfileThe user profile to register
passwordstringThe password for the new user
Returns
- bool
True if registration successful, false otherwise
UserExists(string)
Checks if a username already exists in the system
public bool UserExists(string username)
Parameters
usernamestringThe username to check
Returns
- bool
True if username exists, false otherwise
ValidatePasswordStrength(string)
Validates if a password meets security requirements
public bool ValidatePasswordStrength(string password)
Parameters
passwordstringThe password to validate
Returns
- bool
True if password meets requirements, false otherwise
VerifyPassword(string, string)
Verifies a password against a hash
public static bool VerifyPassword(string password, string hash)