authenticate root user via configHelper
This commit is contained in:
@@ -10,6 +10,7 @@ namespace CarCareTracker.Helper
|
|||||||
OpenIDConfig GetOpenIDConfig();
|
OpenIDConfig GetOpenIDConfig();
|
||||||
UserConfig GetUserConfig(ClaimsPrincipal user);
|
UserConfig GetUserConfig(ClaimsPrincipal user);
|
||||||
bool SaveUserConfig(ClaimsPrincipal user, UserConfig configData);
|
bool SaveUserConfig(ClaimsPrincipal user, UserConfig configData);
|
||||||
|
bool AuthenticateRootUser(string username, string password);
|
||||||
string GetLogoUrl();
|
string GetLogoUrl();
|
||||||
string GetServerLanguage();
|
string GetServerLanguage();
|
||||||
bool GetServerEnableShopSupplies();
|
bool GetServerEnableShopSupplies();
|
||||||
@@ -43,6 +44,12 @@ namespace CarCareTracker.Helper
|
|||||||
}
|
}
|
||||||
return logoUrl;
|
return logoUrl;
|
||||||
}
|
}
|
||||||
|
public bool AuthenticateRootUser(string username, string password)
|
||||||
|
{
|
||||||
|
var rootUsername = _config["UserNameHash"];
|
||||||
|
var rootPassword = _config["UserPasswordHash"];
|
||||||
|
return username == rootUsername && password == rootPassword;
|
||||||
|
}
|
||||||
public string GetServerLanguage()
|
public string GetServerLanguage()
|
||||||
{
|
{
|
||||||
var serverLanguage = _config[nameof(UserConfig.UserLanguage)] ?? "en_US";
|
var serverLanguage = _config[nameof(UserConfig.UserLanguage)] ?? "en_US";
|
||||||
|
|||||||
@@ -35,15 +35,18 @@ namespace CarCareTracker.Logic
|
|||||||
private readonly IUserRecordDataAccess _userData;
|
private readonly IUserRecordDataAccess _userData;
|
||||||
private readonly ITokenRecordDataAccess _tokenData;
|
private readonly ITokenRecordDataAccess _tokenData;
|
||||||
private readonly IMailHelper _mailHelper;
|
private readonly IMailHelper _mailHelper;
|
||||||
|
private readonly IConfigHelper _configHelper;
|
||||||
private IMemoryCache _cache;
|
private IMemoryCache _cache;
|
||||||
public LoginLogic(IUserRecordDataAccess userData,
|
public LoginLogic(IUserRecordDataAccess userData,
|
||||||
ITokenRecordDataAccess tokenData,
|
ITokenRecordDataAccess tokenData,
|
||||||
IMailHelper mailHelper,
|
IMailHelper mailHelper,
|
||||||
|
IConfigHelper configHelper,
|
||||||
IMemoryCache memoryCache)
|
IMemoryCache memoryCache)
|
||||||
{
|
{
|
||||||
_userData = userData;
|
_userData = userData;
|
||||||
_tokenData = tokenData;
|
_tokenData = tokenData;
|
||||||
_mailHelper = mailHelper;
|
_mailHelper = mailHelper;
|
||||||
|
_configHelper = configHelper;
|
||||||
_cache = memoryCache;
|
_cache = memoryCache;
|
||||||
}
|
}
|
||||||
public bool CheckIfUserIsValid(int userId)
|
public bool CheckIfUserIsValid(int userId)
|
||||||
@@ -412,21 +415,9 @@ namespace CarCareTracker.Logic
|
|||||||
}
|
}
|
||||||
private bool UserIsRoot(LoginModel credentials)
|
private bool UserIsRoot(LoginModel credentials)
|
||||||
{
|
{
|
||||||
var configFileContents = File.ReadAllText(StaticHelper.UserConfigPath);
|
var hashedUserName = GetHash(credentials.UserName);
|
||||||
var existingUserConfig = JsonSerializer.Deserialize<UserConfig>(configFileContents);
|
var hashedPassword = GetHash(credentials.Password);
|
||||||
if (existingUserConfig is not null)
|
return _configHelper.AuthenticateRootUser(hashedUserName, hashedPassword);
|
||||||
{
|
|
||||||
//create hashes of the login credentials.
|
|
||||||
var hashedUserName = GetHash(credentials.UserName);
|
|
||||||
var hashedPassword = GetHash(credentials.Password);
|
|
||||||
//compare against stored hash.
|
|
||||||
if (hashedUserName == existingUserConfig.UserNameHash &&
|
|
||||||
hashedPassword == existingUserConfig.UserPasswordHash)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
private static string GetHash(string value)
|
private static string GetHash(string value)
|
||||||
|
|||||||
Reference in New Issue
Block a user