Password hashing - sync with legacy app.

This commit is contained in:
Andy Howard
2025-01-13 14:50:47 +00:00
parent 4f91faae8b
commit 79436b1a60
9 changed files with 191 additions and 140 deletions
@@ -77,14 +77,6 @@ namespace Sarand.Net.Standard.Base.Dbas
// Database info - schema summary.
IDatabaseInfo CreateDbInfo();
//-------------------------------------------------------------------
// Password utilities.
public enum PasswordHashMethod { MsSql }
/// <summary>Generate password hash using the specified method.</summary>
String EncodePassword_Hex(String password, PasswordHashMethod method = PasswordHashMethod.MsSql);
/// <summary>Compare password to hashed value using the specified method.</summary>
bool ComparePassword_Hex(String password, String passwordHashHex, ISacsDatabase.PasswordHashMethod method = ISacsDatabase.PasswordHashMethod.MsSql);
//-------------------------------------------------------------------
// Query records.
String GetSelectQueryPrefix();
@@ -160,12 +160,12 @@ namespace Sarand.Net.Standard.Base.Security
/// <summary>Store the password against against the user.</summary>
public abstract bool SetPassword(SaSecurityItem securityItemUser, String password);
/// <summary>Does the password match that currently defined against the user.</summary>
public abstract bool PasswordMatches(SaSecurityItem securityItemUser, String password);
/// <summary>Is the password currently defined against the user blank.</summary>
public abstract bool PasswordIsBlank(SaSecurityItem securityItemUser);
/// <summary>Does the password match that currently defined against the user.</summary>
public abstract bool PasswordMatches(SaSecurityItem securityItemUser, String password, DbUpdateInfo dbUpdateInfo);
/// <summary>Show form to change password for currently logged in user.</summary>
/// <returns>Flag to indicate password changed</returns>
public abstract bool ShowChangePasswordForm(DbUpdateInfo dbUpdateInfo);
@@ -305,32 +305,32 @@ namespace Sarand.Net.Standard.Base.Security
}
// Security.
[Obsolete("Avoid using the original C++ password encryption - switch to hashed password instead.")]
public String PasswordEncrypted
{
get { return data.PasswordEncrypted; }
set { data.PasswordEncrypted = value; }
}
public String PasswordSalt
{
get { return data.PasswordSalt; }
set { data.PasswordSalt = value; }
protected set { data.PasswordSalt = value; }
}
public String PasswordHash
{
get { return data.PasswordHash; }
set { data.PasswordHash = value; }
protected set { data.PasswordHash = value; }
}
public List<String> PasswordHistory
[Obsolete("Avoid using the original C++ password encryption - switch to hashed password instead.")]
public String PasswordEncrypted
{
get { return data.PasswordHistory; }
set { data.PasswordHistory = value; }
get { return data.PasswordEncrypted; }
protected set { data.PasswordEncrypted = value; }
}
public String PasswordToken
{
get { return data.PasswordToken; }
set { data.PasswordToken = value; }
}
public List<String> PasswordHistory
{
get { return data.PasswordHistory; }
set { data.PasswordHistory = value; }
}
public DateTime PasswordChangedAt
{
get { return data.PasswordChangedAt; }
@@ -368,6 +368,8 @@ namespace Sarand.Net.Standard.Base.Security
/// <summary>Extract password storage method from data.</summary>
public SaSecurity.PasswordMethod GetPasswordMethod()
{
if (PasswordSalt == PasswordSalt_MsSql && !StringUtil.IsBlank(PasswordHash))
return SaSecurity.PasswordMethod.MsSql;
return SaSecurity.PasswordMethod.Legacy;
}
@@ -35,16 +35,23 @@ namespace Sarand.Net.Standard.Base.Security
//-------------------------------------------------------------------
// Password utilities.
public enum PasswordHashMethod { MsSql }
/// <summary>Store the password against against the user.</summary>
public abstract bool SetPassword(SaSecurityItem securityItemUser, String password);
/// <summary>Does the password match that currently defined against the user.</summary>
public abstract bool PasswordMatches(SaSecurityItem securityItemUser, String password);
public abstract bool PasswordMatches(SaSecurityItem securityItemUser, String password, DbUpdateInfo dbUpdateInfo);
/// <summary>Is the password currently defined against the user blank.</summary>
public abstract bool PasswordIsBlank(SaSecurityItem securityItemUser);
/// <summary>Generate password hash using the specified method.</summary>
public abstract String EncodePassword_Hex(String password, PasswordHashMethod method = PasswordHashMethod.MsSql);
/// <summary>Compare password to hashed value using the specified method.</summary>
public abstract bool ComparePassword_Hex(String password, String passwordHashHex, PasswordHashMethod method = PasswordHashMethod.MsSql);
//-------------------------------------------------------------------
}
//=======================================================================