added hashing and implemented it for the masterpassword on login

This commit is contained in:
Taarly 2025-04-28 15:36:11 +02:00
parent a4d553db21
commit 7bf89dfeb8
2 changed files with 26 additions and 3 deletions

View File

@ -0,0 +1,23 @@
using System.Security.Cryptography;
using System.Text;
namespace Project.Persistence;
public static class ShaHash
{
public static string HashPassword(string password)
{
using (SHA256 sha256Hash = SHA256.Create())
{
// convert string to byte array and hash
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(password));
// Byte-Array als Hex-String formatieren
StringBuilder builder = new StringBuilder();
foreach (var b in bytes)
{
builder.Append(b.ToString("x2")); // x2 = hex format
}
return builder.ToString();
}
}
}

View File

@ -26,13 +26,13 @@ public partial class NewLogin : Window
string username = NewLoginUsernameBox.Text?.Trim();
string password = NewLoginPasswordBox.Text?.Trim();
string email = NewLoginEmailBox.Text?.Trim();
var user = new Model.NewUser(username, password, email);
string hashedPassword = ShaHash.HashPassword(password);
var user = new Model.NewUser(username, hashedPassword, email);
SQLite.SaveUser(user);
Close();
}
private void NewLoginCancelOnClick(object? sender, RoutedEventArgs e)
{
Close();