implemented input sanitization for login creation but only with an exception for now

This commit is contained in:
Taarly 2025-05-06 09:01:40 +02:00
parent 0340ad662d
commit 86e9c8f6f3
4 changed files with 10 additions and 8 deletions

View File

@ -1,20 +1,21 @@
namespace Project.Controller; namespace Project.Controller;
public class InputSanitizer public partial class InputSanitizer
{ {
//MasterLogin - Password Check
public static bool MasterLoginPasswordBool(string password) public static bool MasterLoginPasswordBool(string password)
{ {
if (string.IsNullOrEmpty(password) || password.Length < 6) return false; if (string.IsNullOrEmpty(password) || password.Length < 6) return false;
else return true; else return true;
} }
//MasterLogin - Email Check
public static bool MasterLoginEmailBool(string email) public static bool MasterLoginEmailBool(string email)
{ {
if (string.IsNullOrEmpty(email)) return false; if (string.IsNullOrEmpty(email)) return false;
if (email.Contains('@') && email.Length > 6) return true; if (email.Contains('@') && email.Length > 6) return true;
else return false; else return false;
} }
//MasterLogin - Name Check
public static bool MasterLoginNameBool(string username) public static bool MasterLoginNameBool(string username)
{ {
if (string.IsNullOrEmpty(username) || username.Length < 4) return false; if (string.IsNullOrEmpty(username) || username.Length < 4) return false;

View File

@ -2,7 +2,7 @@
public class Entry public class Entry
{ {
public string? Entryname; public string? Name;
public string? Username; public string? Username;
public string? Password; public string? Password;
public string? Url; public string? Url;

View File

@ -2,7 +2,7 @@ using Microsoft.Data.Sqlite;
using Project.Model; using Project.Model;
namespace Project.Persistence; namespace Project.Persistence;
public class SQLite public partial class SQLite
{ {
//filepath for home-pc: //filepath for home-pc:
//private static string _dbPath = "C:/Users/Soi/Project_Keywi/keywi.db"; //private static string _dbPath = "C:/Users/Soi/Project_Keywi/keywi.db";
@ -40,7 +40,7 @@ public class SQLite
command.ExecuteNonQuery(); 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) public static void SaveUser(NewUser user)
{ {
using var connection = new SqliteConnection($"Data Source={_dbPath}"); using var connection = new SqliteConnection($"Data Source={_dbPath}");

View File

@ -1,3 +1,4 @@
using System;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Media; using Avalonia.Media;
@ -31,14 +32,14 @@ public partial class NewLogin : Window
bool masterLoginEmailBool = InputSanitizer.MasterLoginEmailBool(email); bool masterLoginEmailBool = InputSanitizer.MasterLoginEmailBool(email);
bool masterLoginNameBool = InputSanitizer.MasterLoginNameBool(username); bool masterLoginNameBool = InputSanitizer.MasterLoginNameBool(username);
//give strings to appcontroller and keep working on them there //give strings to appcontroller and keep working on them there
if (masterLoginPasswordBool || masterLoginEmailBool || masterLoginNameBool) if (masterLoginPasswordBool && masterLoginEmailBool && masterLoginNameBool)
{ {
AppController.NewLoginSave(username, password, email); AppController.NewLoginSave(username, password, email);
Close(); Close();
} }
else else
{ {
throw new Exception("Master Login Creation Failed");
} }
} }