Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions csharp-password-hash/csharp-password-hash/Hashing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ public static bool CheckPassword(string password, string salt, string hash, Hash
};
}

public static string GenerateSalt()
public static string GenerateSalt(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
var random = new Random((int)DateTime.Now.Ticks & 0x0000FFFF);
return new string(
Enumerable.Repeat(chars, 8)
Enumerable.Repeat(chars, length == 0 ? 8 : length)
.Select(s => s[random.Next(s.Length)])
.ToArray());
}
Expand Down
1 change: 1 addition & 0 deletions csharp-password-hash/csharp-password-hash/HashingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class HashingConfig
[ObsoleteAttribute("Use GeneratePerPasswordSalt instead", false)]
public bool GenratePerPasswordSalt { get { return GeneratePerPasswordSalt; } set { GeneratePerPasswordSalt = value; } }
public bool GeneratePerPasswordSalt { get; set; }
public int PerPasswordSaltLength { get; set; }
public string GlobalSalt { get; set; }

public string SaltedPasswordFormat { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public bool CheckPassword(string password, HashingConfig passwordEncryption,
public string GetHash(string password, HashingConfig hashConfig)
{
var salt = hashConfig.GeneratePerPasswordSalt
? Hashing.GenerateSalt()
? Hashing.GenerateSalt(hashConfig.PerPasswordSaltLength)
: hashConfig.GlobalSalt;

var saltedPassword = GetSaltedPassword(password, salt, hashConfig.SaltedPasswordFormat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>Latest</LangVersion>
<RootNamespace>CSharpPasswordHash</RootNamespace>
<Configurations>Debug;Release;BUAT;PUAT</Configurations>
</PropertyGroup>

<ItemGroup>
Expand Down