started adding input san for masterlogin creation

This commit is contained in:
Taarly 2025-05-05 16:57:14 +02:00
parent 0e8203eadd
commit 0340ad662d
3 changed files with 40 additions and 6 deletions

View File

@ -2,7 +2,7 @@
using Project.Model; using Project.Model;
namespace Project.Controller; namespace Project.Controller;
public class AppController public partial class AppController
{ {
public static void NewLoginSave(string username, string password, string email) public static void NewLoginSave(string username, string password, string email)
{ {

View File

@ -0,0 +1,23 @@
namespace Project.Controller;
public class InputSanitizer
{
public static bool MasterLoginPasswordBool(string password)
{
if (string.IsNullOrEmpty(password) || password.Length < 6) return false;
else return true;
}
public static bool MasterLoginEmailBool(string email)
{
if (string.IsNullOrEmpty(email)) return false;
if (email.Contains('@') && email.Length > 6) return true;
else return false;
}
public static bool MasterLoginNameBool(string username)
{
if (string.IsNullOrEmpty(username) || username.Length < 4) return false;
else return true;
}
}

View File

@ -23,12 +23,23 @@ public partial class NewLogin : Window
private void NewLoginSaveOnClick(object? sender, RoutedEventArgs e) private void NewLoginSaveOnClick(object? sender, RoutedEventArgs e)
{ {
string username = NewLoginUsernameBox.Text?.Trim(); string username = NewLoginUsernameBox.Text?.Trim() ?? string.Empty;
string password = NewLoginPasswordBox.Text?.Trim(); string password = NewLoginPasswordBox.Text?.Trim() ?? string.Empty;
string email = NewLoginEmailBox.Text?.Trim(); string email = NewLoginEmailBox.Text?.Trim() ?? string.Empty;
//test inputs:
bool masterLoginPasswordBool = InputSanitizer.MasterLoginPasswordBool(password);
bool masterLoginEmailBool = InputSanitizer.MasterLoginEmailBool(email);
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
AppController.NewLoginSave(username, password, email); if (masterLoginPasswordBool || masterLoginEmailBool || masterLoginNameBool)
Close(); {
AppController.NewLoginSave(username, password, email);
Close();
}
else
{
}
} }
private void NewLoginCancelOnClick(object? sender, RoutedEventArgs e) private void NewLoginCancelOnClick(object? sender, RoutedEventArgs e)