From 86e9c8f6f39ccc18b9edd85dad8e26edfb6632da Mon Sep 17 00:00:00 2001 From: Taarly Date: Tue, 6 May 2025 09:01:40 +0200 Subject: [PATCH] implemented input sanitization for login creation but only with an exception for now --- Project.Controller/InputSanitizer.cs | 7 ++++--- Project.Model/Entry.cs | 2 +- Project.Persistence/SQLite.cs | 4 ++-- Project.View/NewLogin/NewLogin.axaml.cs | 5 +++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Project.Controller/InputSanitizer.cs b/Project.Controller/InputSanitizer.cs index 4c321d1..823133e 100644 --- a/Project.Controller/InputSanitizer.cs +++ b/Project.Controller/InputSanitizer.cs @@ -1,20 +1,21 @@ namespace Project.Controller; -public class InputSanitizer +public partial class InputSanitizer { + //MasterLogin - Password Check public static bool MasterLoginPasswordBool(string password) { if (string.IsNullOrEmpty(password) || password.Length < 6) return false; else return true; } - + //MasterLogin - Email Check public static bool MasterLoginEmailBool(string email) { if (string.IsNullOrEmpty(email)) return false; if (email.Contains('@') && email.Length > 6) return true; else return false; } - + //MasterLogin - Name Check public static bool MasterLoginNameBool(string username) { if (string.IsNullOrEmpty(username) || username.Length < 4) return false; diff --git a/Project.Model/Entry.cs b/Project.Model/Entry.cs index 93dd559..6926917 100644 --- a/Project.Model/Entry.cs +++ b/Project.Model/Entry.cs @@ -2,7 +2,7 @@ public class Entry { - public string? Entryname; + public string? Name; public string? Username; public string? Password; public string? Url; diff --git a/Project.Persistence/SQLite.cs b/Project.Persistence/SQLite.cs index 30117d9..e10f9b1 100644 --- a/Project.Persistence/SQLite.cs +++ b/Project.Persistence/SQLite.cs @@ -2,7 +2,7 @@ using Microsoft.Data.Sqlite; using Project.Model; namespace Project.Persistence; -public class SQLite +public partial class SQLite { //filepath for home-pc: //private static string _dbPath = "C:/Users/Soi/Project_Keywi/keywi.db"; @@ -40,7 +40,7 @@ public class SQLite command.ExecuteNonQuery(); } - //saves a new user to the table LOGINS ----- no input sanitization yet + //saves a new user to the table LOGINS public static void SaveUser(NewUser user) { using var connection = new SqliteConnection($"Data Source={_dbPath}"); diff --git a/Project.View/NewLogin/NewLogin.axaml.cs b/Project.View/NewLogin/NewLogin.axaml.cs index d047fa2..5be1bcd 100644 --- a/Project.View/NewLogin/NewLogin.axaml.cs +++ b/Project.View/NewLogin/NewLogin.axaml.cs @@ -1,3 +1,4 @@ +using System; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Media; @@ -31,14 +32,14 @@ public partial class NewLogin : Window bool masterLoginEmailBool = InputSanitizer.MasterLoginEmailBool(email); bool masterLoginNameBool = InputSanitizer.MasterLoginNameBool(username); //give strings to appcontroller and keep working on them there - if (masterLoginPasswordBool || masterLoginEmailBool || masterLoginNameBool) + if (masterLoginPasswordBool && masterLoginEmailBool && masterLoginNameBool) { AppController.NewLoginSave(username, password, email); Close(); } else { - + throw new Exception("Master Login Creation Failed"); } }