From 8fe00e3aca0c717b27a09dae5f084357085ab1bc Mon Sep 17 00:00:00 2001 From: Taarly Date: Tue, 29 Apr 2025 09:20:51 +0200 Subject: [PATCH] removed hashing and saving to sql from view and moved it to appcontroller --- Project.Controller/AppController.cs | 11 +++++++++-- Project.Persistence/ShaHash.cs | 4 ++-- Project.View/NewLogin/NewLogin.axaml.cs | 6 ++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Project.Controller/AppController.cs b/Project.Controller/AppController.cs index 8b44008..3620251 100644 --- a/Project.Controller/AppController.cs +++ b/Project.Controller/AppController.cs @@ -1,6 +1,13 @@ -namespace Project.Controller; +using Project.Persistence; +using Project.Model; +namespace Project.Controller; 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); + } } diff --git a/Project.Persistence/ShaHash.cs b/Project.Persistence/ShaHash.cs index 6ee8185..3c7b5e2 100644 --- a/Project.Persistence/ShaHash.cs +++ b/Project.Persistence/ShaHash.cs @@ -11,11 +11,11 @@ public static class ShaHash // convert string to byte array and hash 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(); foreach (var b in bytes) { - builder.Append(b.ToString("x2")); // x2 = hex format + builder.Append(b.ToString("x2")); } return builder.ToString(); } diff --git a/Project.View/NewLogin/NewLogin.axaml.cs b/Project.View/NewLogin/NewLogin.axaml.cs index 7fb5aed..c5abe36 100644 --- a/Project.View/NewLogin/NewLogin.axaml.cs +++ b/Project.View/NewLogin/NewLogin.axaml.cs @@ -26,10 +26,8 @@ public partial class NewLogin : Window string username = NewLoginUsernameBox.Text?.Trim(); string password = NewLoginPasswordBox.Text?.Trim(); string email = NewLoginEmailBox.Text?.Trim(); - string hashedPassword = ShaHash.HashPassword(password); - var user = new Model.NewUser(username, hashedPassword, email); - SQLite.SaveUser(user); - + //give strings to appcontroller and keep working on them there + AppController.NewLoginSave(username, password, email); Close(); }