HES SAVIN

This commit is contained in:
taarly 2025-04-18 20:26:08 +02:00
parent e3232e4bee
commit a6ba0f388f
5 changed files with 38 additions and 16 deletions

View File

@ -1,12 +1,12 @@
namespace Project.Model; namespace Project.Model;
public class CreateLogin public class NewUser
{ {
public string NewLoginName { get; set; } public string NewLoginName { get; set; }
public string NewMasterPassword { get; set; } public string NewMasterPassword { get; set; }
public string NewEmail { get; set; } public string NewEmail { get; set; }
public CreateLogin(string username, string password, string email) public NewUser(string username, string password, string email)
{ {
NewLoginName = username; NewLoginName = username;
NewMasterPassword = password; NewMasterPassword = password;

View File

@ -1,11 +1,16 @@
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
using Project.Model;
namespace Project.Persistence; namespace Project.Persistence;
public class SQLite public class SQLite
{ {
private string _dbPath = "C:/Users/lowns/Desktop/logins.db"; private static string _dbPath = "C:/Users/Soi/Project_Keywi/logins.db";
//KLASSENVARIABLEN ERSTELLEN
public void Init() //private static string loginname;
//checks if there is a sqlite database in _dbPath on programm startup, if not -> creates the database and a table LOGINS
public static void Init()
{ {
using var connection = new SqliteConnection($"Data Source={_dbPath}"); using var connection = new SqliteConnection($"Data Source={_dbPath}");
connection.Open(); connection.Open();
@ -13,7 +18,7 @@ public class SQLite
var command = connection.CreateCommand(); var command = connection.CreateCommand();
command.CommandText = command.CommandText =
@" @"
CREATE TABLE IF NOT EXISTS logins ( CREATE TABLE IF NOT EXISTS LOGINS (
loginname STRING PRIMARY KEY NOT NULL, loginname STRING PRIMARY KEY NOT NULL,
loginpass STRING NOT NULL, loginpass STRING NOT NULL,
loginemail STRING NOT NULL loginemail STRING NOT NULL
@ -21,4 +26,25 @@ public class SQLite
"; ";
command.ExecuteNonQuery(); command.ExecuteNonQuery();
} }
//saves a new user to the table LOGINS ----- no input sanitization yet
public static void SaveUser(NewUser user)
{
using var connection = new SqliteConnection($"Data Source={_dbPath}");
connection.Open();
connection.Open();
using (var command = connection.CreateCommand())
{
command.Parameters.AddWithValue("@loginname", user.NewLoginName);
command.Parameters.AddWithValue("@loginpass", user.NewMasterPassword);
command.Parameters.AddWithValue("@loginemail", user.NewEmail);
command.CommandText =
@"
INSERT INTO LOGINS (loginname, loginpass, loginemail)
VALUES (@loginname, @loginpass, @loginemail);";
command.ExecuteNonQuery();
}
}
} }

View File

@ -1,9 +1,11 @@
using Project.Model; using Project.Model;
using Microsoft.Data.Sqlite;
namespace Project.Persistence; namespace Project.Persistence;
public static class SaveNewLogin public static class SaveNewLogin
{ {
public static void SaveUser(string username, string password, string email) public static void SaveUser(NewUser user)
{ {
} }

View File

@ -18,8 +18,7 @@ public partial class App : Application
{ {
desktop.MainWindow = new MainWindow(); desktop.MainWindow = new MainWindow();
// Initialising the database that contains all the logins // Initialising the database that contains all the logins
var initdb = new SQLite(); SQLite.Init();
initdb.Init();
} }
base.OnFrameworkInitializationCompleted(); base.OnFrameworkInitializationCompleted();

View File

@ -27,13 +27,8 @@ public partial class NewLogin : Window
string password = NewLoginPasswordBox.Text?.Trim(); string password = NewLoginPasswordBox.Text?.Trim();
string email = NewLoginEmailBox.Text?.Trim(); string email = NewLoginEmailBox.Text?.Trim();
//var user = new CreateLogin(username, password, email); var user = new Model.NewUser(username, password, email);
//SaveNewLogin.SaveUser(user); SQLite.SaveUser(user);
NewLoginUsernameBox.Text = "";
NewLoginPasswordBox.Text = "";
NewLoginEmailBox.Text = "";
Close(); Close();