Skip to content

Commit

Permalink
RandomPassword class naming change
Browse files Browse the repository at this point in the history
  • Loading branch information
Haik committed Nov 6, 2023
1 parent e686b91 commit 25a21b9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions Pandatech.Crypto.Tests/Argon2IdTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public void HashVerify_ShouldFailForDifferentArgonConfigs()
{
var argon2Id = new Argon2Id();
var argon2Id2 = new Argon2Id(new Argon2IdOptions { SaltSize = 16, MemorySize = 128, DegreeOfParallelism = 1, Iterations = 1 });
var password = RandomPassword.Generate(32, true, true, true, true);
var password = Password.GenerateRandom(32, true, true, true, true);
var hash = argon2Id.HashPassword(password);
Assert.False(argon2Id2.VerifyHash(password, hash));
}
Expand All @@ -17,7 +17,7 @@ public void HashVerify_ShouldBeValid()
{
var argon2Id = new Argon2Id();

var password = RandomPassword.Generate(32, true, true, true, true);
var password = Password.GenerateRandom(32, true, true, true, true);
var hash = argon2Id.HashPassword(password);

Assert.True(argon2Id.VerifyHash(password, hash));
Expand All @@ -27,7 +27,7 @@ public void HashVerify_ShouldBeValid()
public void HashVerify_InvalidPassword_ShouldBeInvalid()
{
var argon2Id = new Argon2Id();
var password = RandomPassword.Generate(32, true, true, true, true);
var password = Password.GenerateRandom(32, true, true, true, true);
var hash = argon2Id.HashPassword(password);
Assert.False(argon2Id.VerifyHash("SomePassword", hash));
}
Expand All @@ -36,8 +36,8 @@ public void HashVerify_InvalidPassword_ShouldBeInvalid()
public void DifferentPasswords_ShouldHaveDifferentHashes()
{
var argon2Id = new Argon2Id();
var password1 = RandomPassword.Generate(32, true, true, true, true);
var password2 = RandomPassword.Generate(32, true, true, true, true);
var password1 = Password.GenerateRandom(32, true, true, true, true);
var password2 = Password.GenerateRandom(32, true, true, true, true);
var hash1 = argon2Id.HashPassword(password1);
var hash2 = argon2Id.HashPassword(password2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Pandatech.Crypto.Tests;

public class RandomPasswordTests
public class PasswordTests
{
[Theory]
[InlineData(7, true, true, true, true)]
Expand All @@ -14,7 +14,7 @@ public void Generate_ShouldReturnPasswordWithCorrectProperties(
bool includeSpecialChars)
{
// Generate a random password
var password = RandomPassword.Generate(length, includeUppercase, includeLowercase, includeDigits,
var password = Password.GenerateRandom(length, includeUppercase, includeLowercase, includeDigits,
includeSpecialChars);

// Check if the password length is correct
Expand All @@ -34,8 +34,8 @@ public void Generate_ShouldReturnPasswordWithCorrectProperties(
[Fact]
public void Generate_ShouldReturnDifferentPasswords()
{
var password1 = RandomPassword.Generate(12, true, true, true, true);
var password2 = RandomPassword.Generate(12, true, true, true, true);
var password1 = Password.GenerateRandom(12, true, true, true, true);
var password2 = Password.GenerateRandom(12, true, true, true, true);

Assert.NotEqual(password1, password2);
}
Expand All @@ -56,9 +56,9 @@ public void ValidationTestForGeneratedPasswords(
bool includeSpecialChars)
{
// Generate a random password
var password = RandomPassword.Generate(length, includeUppercase, includeLowercase, includeDigits,
var password = Password.GenerateRandom(length, includeUppercase, includeLowercase, includeDigits,
includeSpecialChars);
Assert.True(RandomPassword.Validate(password, length, includeUppercase, includeLowercase, includeDigits,
Assert.True(Password.Validate(password, length, includeUppercase, includeLowercase, includeDigits,
includeSpecialChars));
}
[Theory]
Expand All @@ -76,9 +76,9 @@ public void ValidationTestForGeneratedPasswordsOpposite(
bool includeSpecialChars)
{
// Generate a random password
var password = RandomPassword.Generate(length, includeUppercase, includeLowercase, includeDigits,
var password = Password.GenerateRandom(length, includeUppercase, includeLowercase, includeDigits,
includeSpecialChars);
Assert.False(RandomPassword.Validate(password, length, !includeUppercase, !includeLowercase, !includeDigits,
Assert.False(Password.Validate(password, length, !includeUppercase, !includeLowercase, !includeDigits,
!includeSpecialChars));
}
}
4 changes: 2 additions & 2 deletions Pandatech.Crypto/Pandatech.Crypto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.1.6</Version>
<Version>2.1.7</Version>
<Title>Pandatech.Crypto</Title>
<Authors>Pandatech</Authors>
<PackageIcon>pandatech.png</PackageIcon>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Description>PandaTech.Crypto is a .NET library simplifying common cryptograhic functions.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-pandatech-crypto</RepositoryUrl>
<PackageReleaseNotes>Added password validator</PackageReleaseNotes>
<PackageReleaseNotes>Changed RandomPassword to Password</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace Pandatech.Crypto;

public static class RandomPassword
public static class Password
{
private const string UppercaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private const string LowercaseChars = "abcdefghijklmnopqrstuvwxyz";
private const string DigitChars = "0123456789";
private const string SpecialChars = "!@#$%^&*()-_=+[]{}|;:'\",.<>?";

public static string Generate(int length, bool includeUppercase, bool includeLowercase, bool includeDigits,
public static string GenerateRandom(int length, bool includeUppercase, bool includeLowercase, bool includeDigits,
bool includeSpecialChars)
{
var typesCount = ValidateInput(length, includeUppercase, includeLowercase, includeDigits, includeSpecialChars);
Expand Down
6 changes: 3 additions & 3 deletions Pandatech.Crypto/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var randomBytes = Random.GenerateBytes(16);
var aesKey = Random.GenerateAes256KeyString();
```

### 4. RandomPassword Class
### 4. Password Class

```csharp
var includeUppercase = true;
Expand All @@ -120,10 +120,10 @@ var includeDigits = true;
var includeSpecialChars = true;

//Method for generating random password
string password = RandomPassword.Generate(16, includeUppercase, includeLowercase, includeDigits, includeSpecialChars);
string password = Password.GenerateRandom(16, includeUppercase, includeLowercase, includeDigits, includeSpecialChars);

//Method for validation of password
bool isValid = RandomPassword.Validate(password, 16, includeUppercase, includeLowercase, includeDigits, includeSpecialChars);
bool isValid = Password.Validate(password, 16, includeUppercase, includeLowercase, includeDigits, includeSpecialChars);
```

### 5. Sha3 Class
Expand Down
6 changes: 3 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var randomBytes = Random.GenerateBytes(16);
var aesKey = Random.GenerateAes256KeyString();
```

### 4. RandomPassword Class
### 4. Password Class

```csharp
var includeUppercase = true;
Expand All @@ -120,10 +120,10 @@ var includeDigits = true;
var includeSpecialChars = true;

//Method for generating random password
string password = RandomPassword.Generate(16, includeUppercase, includeLowercase, includeDigits, includeSpecialChars);
string password = Password.GenerateRandom(16, includeUppercase, includeLowercase, includeDigits, includeSpecialChars);

//Method for validation of password
bool isValid = RandomPassword.Validate(password, 16, includeUppercase, includeLowercase, includeDigits, includeSpecialChars);
bool isValid = Password.Validate(password, 16, includeUppercase, includeLowercase, includeDigits, includeSpecialChars);
```

### 5. Sha3 Class
Expand Down

0 comments on commit 25a21b9

Please sign in to comment.