added hashing and implemented it for the masterpassword on login
This commit is contained in:
parent
a4d553db21
commit
7bf89dfeb8
23
Project.Persistence/ShaHash.cs
Normal file
23
Project.Persistence/ShaHash.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user