Enhance authentication features and dependencies
Updated `DigitalData.Auth.API.csproj` to include new package references for improved security and functionality. Added a `Verify` method in the `Backdoor` class to securely check user credentials against plain text and hashed passwords. Introduced `BackdoorExtensions` with methods for easier retrieval of `Backdoor` instances by username.
This commit is contained in:
parent
019abaffa6
commit
c3794f1e65
@ -10,6 +10,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||||
<PackageReference Include="DigitalData.Core.Abstractions" Version="3.4.0" />
|
<PackageReference Include="DigitalData.Core.Abstractions" Version="3.4.0" />
|
||||||
<PackageReference Include="DigitalData.Core.Abstractions.Security" Version="1.0.0" />
|
<PackageReference Include="DigitalData.Core.Abstractions.Security" Version="1.0.0" />
|
||||||
<PackageReference Include="DigitalData.Core.Application" Version="3.2.0" />
|
<PackageReference Include="DigitalData.Core.Application" Version="3.2.0" />
|
||||||
|
|||||||
@ -7,4 +7,15 @@ public class Backdoor
|
|||||||
public string? Password { get; init; }
|
public string? Password { get; init; }
|
||||||
|
|
||||||
public string? PasswordHash { get; init; }
|
public string? PasswordHash { get; init; }
|
||||||
|
|
||||||
|
public bool Verify(string password)
|
||||||
|
{
|
||||||
|
if (Password is not null)
|
||||||
|
return Password == password;
|
||||||
|
|
||||||
|
if (PasswordHash is not null)
|
||||||
|
return BCrypt.Net.BCrypt.Verify(password, PasswordHash);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
src/DigitalData.Auth.API/Models/BackdoorExtensions.cs
Normal file
8
src/DigitalData.Auth.API/Models/BackdoorExtensions.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace DigitalData.Auth.API.Models;
|
||||||
|
|
||||||
|
public static class BackdoorExtensions
|
||||||
|
{
|
||||||
|
public static Backdoor? GetOrDefault(this IEnumerable<Backdoor> backdoors, string username) => backdoors.Where(b => b.Username == username).FirstOrDefault();
|
||||||
|
|
||||||
|
public static Backdoor? TryGet(this IEnumerable<Backdoor> backdoors, string username) => backdoors.Where(b => b.Username == username).FirstOrDefault();
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user