aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/api/api/Models/PasswordCrypt.cs27
-rw-r--r--backend/api/api/api.csproj4
2 files changed, 29 insertions, 2 deletions
diff --git a/backend/api/api/Models/PasswordCrypt.cs b/backend/api/api/Models/PasswordCrypt.cs
new file mode 100644
index 00000000..016fde51
--- /dev/null
+++ b/backend/api/api/Models/PasswordCrypt.cs
@@ -0,0 +1,27 @@
+namespace api.Models
+{
+ public class PasswordCrypt
+ {
+ private static int difficulty = 10;
+
+ public static String hashPassword(String password)
+ {
+ String salt = BCrypt.Net.BCrypt.GenerateSalt(difficulty);
+ String passwordHash = BCrypt.Net.BCrypt.HashPassword(password, salt);
+
+ return passwordHash;
+ }
+ public static Boolean checkPassword(String plainText,String hash)
+ {
+ Boolean verified = false;
+
+ if (hash == null || !hash.StartsWith("$2a$"))
+ throw new ArgumentException("invalid hash");
+
+ verified=BCrypt.Net.BCrypt.Verify(plainText, hash);
+
+ return verified;
+
+ }
+ }
+}
diff --git a/backend/api/api/api.csproj b/backend/api/api/api.csproj
index f278c90a..97b88d00 100644
--- a/backend/api/api/api.csproj
+++ b/backend/api/api/api.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk.Web">
+<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
- <Folder Include="Controllers\" />
+ <PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
</ItemGroup>
</Project>