removed hashing and saving to sql from view and moved it to appcontroller

This commit is contained in:
Taarly 2025-04-29 09:20:51 +02:00
parent 7bf89dfeb8
commit 8fe00e3aca
3 changed files with 13 additions and 8 deletions

View File

@ -1,6 +1,13 @@
namespace Project.Controller; using Project.Persistence;
using Project.Model;
namespace Project.Controller;
public class AppController public class AppController
{ {
public static void NewLoginSave(string username, string password, string email)
{
string hashedPassword = ShaHash.HashPassword(password);
var user = new Model.NewUser(username, hashedPassword, email);
SQLite.SaveUser(user);
}
} }

View File

@ -11,11 +11,11 @@ public static class ShaHash
// convert string to byte array and hash // convert string to byte array and hash
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(password)); byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(password));
// Byte-Array als Hex-String formatieren // convert byte array to hex-string - x2 = hex format
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
foreach (var b in bytes) foreach (var b in bytes)
{ {
builder.Append(b.ToString("x2")); // x2 = hex format builder.Append(b.ToString("x2"));
} }
return builder.ToString(); return builder.ToString();
} }

View File

@ -26,10 +26,8 @@ public partial class NewLogin : Window
string username = NewLoginUsernameBox.Text?.Trim(); string username = NewLoginUsernameBox.Text?.Trim();
string password = NewLoginPasswordBox.Text?.Trim(); string password = NewLoginPasswordBox.Text?.Trim();
string email = NewLoginEmailBox.Text?.Trim(); string email = NewLoginEmailBox.Text?.Trim();
string hashedPassword = ShaHash.HashPassword(password); //give strings to appcontroller and keep working on them there
var user = new Model.NewUser(username, hashedPassword, email); AppController.NewLoginSave(username, password, email);
SQLite.SaveUser(user);
Close(); Close();
} }