Skip to content

Commit

Permalink
Renaming PasswordGenerator to PasswordFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
YassinLokhat committed Feb 7, 2025
1 parent 71e1761 commit a944379
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Core/Internal/Models/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ internal bool PasswordExpired
}
}

internal bool PasswordLeaked => Options.ContainsFlag(AccountOption.WarnIfPasswordLeaked) && Database.PasswordGenerator.PasswordLeaked(Password);
internal bool PasswordLeaked => Options.ContainsFlag(AccountOption.WarnIfPasswordLeaked) && Database.PasswordFactory.PasswordLeaked(Password);

public void Apply(Change change)
{
Expand Down
16 changes: 8 additions & 8 deletions Core/Internal/Models/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal sealed class Database : IDatabase

public ICryptographyCenter CryptographyCenter { get; private set; }
public ISerializationCenter SerializationCenter { get; private set; }
public IPasswordGenerator PasswordGenerator { get; private set; }
public IPasswordFactory PasswordFactory { get; private set; }

public event EventHandler<WarningDetectedEventArgs>? WarningDetected;
public event EventHandler<AutoSaveDetectedEventArgs>? AutoSaveDetected;
Expand Down Expand Up @@ -142,7 +142,7 @@ public void Delete()

private Database(ICryptographyCenter cryptographicCenter,
ISerializationCenter serializationCenter,
IPasswordGenerator passwordGenerator,
IPasswordFactory passwordFactory,
string databaseFile,
string autoSaveFile,
string logFile,
Expand All @@ -157,7 +157,7 @@ private Database(ICryptographyCenter cryptographicCenter,

CryptographyCenter = cryptographicCenter;
SerializationCenter = serializationCenter;
PasswordGenerator = passwordGenerator;
PasswordFactory = passwordFactory;

Username = username;
Passkeys = [CryptographyCenter.GetHash(username)];
Expand Down Expand Up @@ -198,7 +198,7 @@ private Database(ICryptographyCenter cryptographicCenter,

internal static IDatabase Create(ICryptographyCenter cryptographicCenter,
ISerializationCenter serializationCenter,
IPasswordGenerator passwordGenerator,
IPasswordFactory passwordFactory,
string databaseFile,
string autoSaveFile,
string logFile,
Expand All @@ -221,7 +221,7 @@ internal static IDatabase Create(ICryptographyCenter cryptographicCenter,

Database database = new(cryptographicCenter,
serializationCenter,
passwordGenerator,
passwordFactory,
databaseFile,
autoSaveFile,
logFile,
Expand All @@ -247,7 +247,7 @@ internal static IDatabase Create(ICryptographyCenter cryptographicCenter,

return Open(cryptographicCenter,
serializationCenter,
passwordGenerator,
passwordFactory,
databaseFile,
autoSaveFile,
logFile,
Expand All @@ -256,15 +256,15 @@ internal static IDatabase Create(ICryptographyCenter cryptographicCenter,

internal static IDatabase Open(ICryptographyCenter cryptographicCenter,
ISerializationCenter serializationCenter,
IPasswordGenerator passwordGenerator,
IPasswordFactory passwordFactory,
string databaseFile,
string autoSaveFile,
string logFile,
string username)
{
Database database = new(cryptographicCenter,
serializationCenter,
passwordGenerator,
passwordFactory,
databaseFile,
autoSaveFile,
logFile,
Expand Down
16 changes: 8 additions & 8 deletions Core/Public/Interfaces/IDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public interface IDatabase : IDisposable
ICryptographyCenter CryptographyCenter { get; }

/// <summary>
/// The password generator implementation.
/// The password factory implementation.
/// </summary>
IPasswordGenerator PasswordGenerator { get; }
IPasswordFactory PasswordFactory { get; }

/// <summary>
/// Occurs when a warning is detected.
Expand Down Expand Up @@ -102,7 +102,7 @@ public interface IDatabase : IDisposable
/// </summary>
/// <param name="cryptographicCenter">An implementation of the cryptographic center.</param>
/// <param name="serializationCenter">An implementation of the serialization center.</param>
/// <param name="passwordGenerator">An implementation of the password generator.</param>
/// <param name="passwordFactory">An implementation of the password factory.</param>
/// <param name="databaseFile">The path to the database file.</param>
/// <param name="autoSaveFile">The path to the autosave file.</param>
/// <param name="logFile">The path to the log file.</param>
Expand All @@ -111,15 +111,15 @@ public interface IDatabase : IDisposable
/// <returns>The database created.</returns>
static IDatabase Create(ICryptographyCenter cryptographicCenter,
ISerializationCenter serializationCenter,
IPasswordGenerator passwordGenerator,
IPasswordFactory passwordFactory,
string databaseFile,
string autoSaveFile,
string logFile,
string username,
string[] passkeys)
=> Internal.Models.Database.Create(cryptographicCenter,
serializationCenter,
passwordGenerator,
passwordFactory,
databaseFile,
autoSaveFile,
logFile,
Expand All @@ -132,22 +132,22 @@ static IDatabase Create(ICryptographyCenter cryptographicCenter,
/// </summary>
/// <param name="cryptographicCenter">An implementation of the cryptographic center.</param>
/// <param name="serializationCenter">An implementation of the serialization center.</param>
/// <param name="passwordGenerator">An implementation of the password generator.</param>
/// <param name="passwordFactory">An implementation of the password factory.</param>
/// <param name="databaseFile">The path to the database file.</param>
/// <param name="autoSaveFile">The path to the autosave file.</param>
/// <param name="logFile">The path to the log file.</param>
/// <param name="username">The username.</param>
/// <returns>The database opened.</returns>
static IDatabase Open(ICryptographyCenter cryptographicCenter,
ISerializationCenter serializationCenter,
IPasswordGenerator passwordGenerator,
IPasswordFactory passwordFactory,
string databaseFile,
string autoSaveFile,
string logFile,
string username)
=> Internal.Models.Database.Open(cryptographicCenter,
serializationCenter,
passwordGenerator,
passwordFactory,
databaseFile,
autoSaveFile,
logFile,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
namespace Upsilon.Apps.PassKey.Core.Public.Interfaces
{
/// <summary>
/// Represent a Password generator engine.
/// Represent a Password factory engine.
/// </summary>
public interface IPasswordGenerator
public interface IPasswordFactory
{
/// <summary>
/// The letters used by the generator.
/// The letters used by the factory.
/// </summary>
public string Alphabetic { get; }

/// <summary>
/// The digits used by the generator.
/// The digits used by the factory.
/// </summary>
public string Numeric { get; }

/// <summary>
/// The special characters used by the generator.
/// The special characters used by the factory.
/// </summary>
public string SpecialChars { get; }

Expand Down
40 changes: 17 additions & 23 deletions Core/Public/Interfaces/Interfaces.cd
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,37 @@
<Point X="10.281" Y="4.896" />
</Path>
</AssociationLine>
<AssociationLine Name="CryptographyCenter" Type="Upsilon.Apps.PassKey.Core.Public.Interfaces.ICryptographyCenter" ManuallyRouted="true" FixedFromPoint="true" FixedToPoint="true">
<AssociationLine Name="SerializationCenter" Type="Upsilon.Apps.PassKey.Core.Public.Interfaces.ISerializationCenter" ManuallyRouted="true" FixedFromPoint="true" FixedToPoint="true">
<Path>
<Point X="9" Y="6.562" />
<Point X="12.333" Y="6.562" />
<Point X="12.333" Y="5.115" />
<Point X="12.75" Y="5.115" />
<Point X="9" Y="5.989" />
<Point X="12.042" Y="5.989" />
<Point X="12.042" Y="0.812" />
<Point X="12.75" Y="0.812" />
</Path>
<MemberNameLabel ManuallyPlaced="true">
<Position X="0.506" Y="-1.357" />
<Position X="0.777" Y="-5.107" />
</MemberNameLabel>
</AssociationLine>
<AssociationLine Name="PasswordGenerator" Type="Upsilon.Apps.PassKey.Core.Public.Interfaces.IPasswordGenerator" FixedFromPoint="true">
<Path>
<Point X="9" Y="7.125" />
<Point X="12.75" Y="7.125" />
</Path>
</AssociationLine>
<AssociationLine Name="SerializationCenter" Type="Upsilon.Apps.PassKey.Core.Public.Interfaces.ISerializationCenter" ManuallyRouted="true" FixedFromPoint="true" FixedToPoint="true">
<AssociationLine Name="CryptographyCenter" Type="Upsilon.Apps.PassKey.Core.Public.Interfaces.ICryptographyCenter" ManuallyRouted="true" FixedFromPoint="true" FixedToPoint="true">
<Path>
<Point X="9" Y="6" />
<Point X="12.042" Y="6" />
<Point X="12.042" Y="0.812" />
<Point X="12.75" Y="0.812" />
<Point X="9" Y="6.525" />
<Point X="12.333" Y="6.525" />
<Point X="12.333" Y="5.115" />
<Point X="12.75" Y="5.115" />
</Path>
<MemberNameLabel ManuallyPlaced="true">
<Position X="0.777" Y="-5.107" />
<Position X="0.506" Y="-1.357" />
</MemberNameLabel>
</AssociationLine>
<TypeIdentifier>
<HashCode>AgABAIgQAAAAoAAARAAACAAggAGEAEAAAAAQAACAAAA=</HashCode>
<HashCode>AgABAIgQAAAAoAAAQAAACAAggAGEAUAAAAAQAACAAAA=</HashCode>
<FileName>Public\Interfaces\IDatabase.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="User" />
<Property Name="CryptographyCenter" />
<Property Name="PasswordGenerator" />
<Property Name="SerializationCenter" />
<Property Name="CryptographyCenter" />
<Property Name="PasswordFactory" />
</ShowAsAssociation>
<ShowAsCollectionAssociation>
<Property Name="Logs" />
Expand Down Expand Up @@ -166,11 +160,11 @@
<Property Name="Accounts" />
</ShowAsCollectionAssociation>
</Interface>
<Interface Name="Upsilon.Apps.PassKey.Core.Public.Interfaces.IPasswordGenerator">
<Interface Name="Upsilon.Apps.PassKey.Core.Public.Interfaces.IPasswordFactory">
<Position X="12.75" Y="6.75" Width="2.5" />
<TypeIdentifier>
<HashCode>AAAAAQAAAAAAAAAAAAAAAAACAAAAAAQAgABAAAAAAAA=</HashCode>
<FileName>Public\Interfaces\IPasswordGenerator.cs</FileName>
<FileName>Public\Interfaces\IPasswordFactory.cs</FileName>
</TypeIdentifier>
</Interface>
<Enum Name="Upsilon.Apps.PassKey.Core.Public.Enums.AccountOption">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Upsilon.Apps.PassKey.Core.Public.Utils
{
public class PasswordGenerator : IPasswordGenerator
public class PasswordFactory : IPasswordFactory
{
public string Alphabetic => "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public string Numeric => "0123456789";
Expand Down
2 changes: 1 addition & 1 deletion UnitTests/Models/DatabaseUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void Case05_DatabaseAutoLogout()
UnitTestsHelper.ClearTestEnvironment();
IDatabase database = IDatabase.Create(UnitTestsHelper.CryptographicCenter,
UnitTestsHelper.SerializationCenter,
UnitTestsHelper.PasswordGenerator,
UnitTestsHelper.PasswordFactory,
databaseFile,
autoSaveFile,
logFile,
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/Models/UserUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void Case02_UserUpdateThenSaved()
// When
IDatabase databaseLoaded = IDatabase.Open(UnitTestsHelper.CryptographicCenter,
UnitTestsHelper.SerializationCenter,
UnitTestsHelper.PasswordGenerator,
UnitTestsHelper.PasswordFactory,
databaseFile,
autoSaveFile,
logFile,
Expand Down Expand Up @@ -195,7 +195,7 @@ public void Case03_UserUpdateButNotSaved()

databaseLoaded = IDatabase.Open(UnitTestsHelper.CryptographicCenter,
UnitTestsHelper.SerializationCenter,
UnitTestsHelper.PasswordGenerator,
UnitTestsHelper.PasswordFactory,
databaseFile,
autoSaveFile,
logFile,
Expand Down
6 changes: 3 additions & 3 deletions UnitTests/UnitTestsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class UnitTestsHelper

public static readonly ICryptographyCenter CryptographicCenter = new CryptographyCenter();
public static readonly ISerializationCenter SerializationCenter = new JsonSerializationCenter();
public static readonly IPasswordGenerator PasswordGenerator = new PasswordGenerator();
public static readonly IPasswordFactory PasswordFactory = new PasswordFactory();

public static string ComputeDatabaseFileDirectory([CallerMemberName] string username = "") => $"./TestFiles/{username}";
public static string ComputeDatabaseFilePath([CallerMemberName] string username = "") => $"{ComputeDatabaseFileDirectory(username)}/{username}.pku";
Expand All @@ -29,7 +29,7 @@ public static IDatabase CreateTestDatabase(string[] passkeys = null, [CallerMemb

IDatabase database = IDatabase.Create(CryptographicCenter,
SerializationCenter,
PasswordGenerator,
PasswordFactory,
databaseFile,
autoSaveFile,
logFile,
Expand All @@ -54,7 +54,7 @@ public static IDatabase OpenTestDatabase(string[] passkeys, out IWarning[] detec

IDatabase database = IDatabase.Open(CryptographicCenter,
SerializationCenter,
PasswordGenerator,
PasswordFactory,
databaseFile,
autoSaveFile,
logFile,
Expand Down

0 comments on commit a944379

Please sign in to comment.