Adds PBKDF2 protection for account passwords. (#122)
This commit is contained in:
parent
1ee6830637
commit
29467a3ed9
9 changed files with 209 additions and 172 deletions
|
|
@ -0,0 +1,30 @@
|
|||
using Xunit;
|
||||
using Server.Accounting;
|
||||
|
||||
namespace Server.Tests.Accounting
|
||||
{
|
||||
public class PBKDF2PasswordProtectionTest
|
||||
{
|
||||
private const string plainPassword = "hello-good-sir";
|
||||
|
||||
[Fact]
|
||||
public void TestValidates()
|
||||
{
|
||||
var passwordProtection = new PBKDF2PasswordProtection();
|
||||
|
||||
string encryptedPassword = passwordProtection.EncryptPassword(plainPassword);
|
||||
|
||||
Assert.True(passwordProtection.ValidatePassword(encryptedPassword, plainPassword));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestPasswordDoesNotValidate()
|
||||
{
|
||||
var passwordProtection = new PBKDF2PasswordProtection();
|
||||
|
||||
string encryptedPassword = passwordProtection.EncryptPassword(plainPassword);
|
||||
|
||||
Assert.False(passwordProtection.ValidatePassword(encryptedPassword, "Not the same password"));
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Projects/Scripts.Tests/Misc/HexStringConverterTest.cs
Normal file
20
Projects/Scripts.Tests/Misc/HexStringConverterTest.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using Xunit;
|
||||
using Server.Misc;
|
||||
|
||||
namespace Server.Tests.Accounting
|
||||
{
|
||||
public class HexStringConverterTest
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("ABCDEF1234", new byte[]{ 0xAB, 0xCD, 0xEF, 0x12, 0x34 })]
|
||||
public void ConvertsProperly(string input, byte[] bytes)
|
||||
{
|
||||
Span<byte> outputBytes = stackalloc byte[input.Length / 2];
|
||||
HexStringConverter.GetBytes(input, outputBytes);
|
||||
|
||||
Assert.Equal(bytes, outputBytes.ToArray());
|
||||
Assert.Equal(input, HexStringConverter.GetString(bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,4 +9,8 @@
|
|||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="1.2.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Server\Server.csproj" />
|
||||
<ProjectReference Include="..\Scripts\Scripts.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue