HES SAVIN
This commit is contained in:
parent
e3232e4bee
commit
a6ba0f388f
@ -1,12 +1,12 @@
|
||||
namespace Project.Model;
|
||||
|
||||
public class CreateLogin
|
||||
public class NewUser
|
||||
{
|
||||
public string NewLoginName { get; set; }
|
||||
public string NewMasterPassword { 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;
|
||||
NewMasterPassword = password;
|
||||
@ -1,11 +1,16 @@
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Project.Model;
|
||||
namespace Project.Persistence;
|
||||
|
||||
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
|
||||
//private static string loginname;
|
||||
|
||||
public void Init()
|
||||
|
||||
//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}");
|
||||
connection.Open();
|
||||
@ -13,7 +18,7 @@ public class SQLite
|
||||
var command = connection.CreateCommand();
|
||||
command.CommandText =
|
||||
@"
|
||||
CREATE TABLE IF NOT EXISTS logins (
|
||||
CREATE TABLE IF NOT EXISTS LOGINS (
|
||||
loginname STRING PRIMARY KEY NOT NULL,
|
||||
loginpass STRING NOT NULL,
|
||||
loginemail STRING NOT NULL
|
||||
@ -21,4 +26,25 @@ public class SQLite
|
||||
";
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,11 @@
|
||||
using Project.Model;
|
||||
|
||||
using Microsoft.Data.Sqlite;
|
||||
namespace Project.Persistence;
|
||||
|
||||
public static class SaveNewLogin
|
||||
{
|
||||
public static void SaveUser(string username, string password, string email)
|
||||
public static void SaveUser(NewUser user)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -18,8 +18,7 @@ public partial class App : Application
|
||||
{
|
||||
desktop.MainWindow = new MainWindow();
|
||||
// Initialising the database that contains all the logins
|
||||
var initdb = new SQLite();
|
||||
initdb.Init();
|
||||
SQLite.Init();
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
|
||||
@ -27,13 +27,8 @@ public partial class NewLogin : Window
|
||||
string password = NewLoginPasswordBox.Text?.Trim();
|
||||
string email = NewLoginEmailBox.Text?.Trim();
|
||||
|
||||
//var user = new CreateLogin(username, password, email);
|
||||
//SaveNewLogin.SaveUser(user);
|
||||
|
||||
|
||||
NewLoginUsernameBox.Text = "";
|
||||
NewLoginPasswordBox.Text = "";
|
||||
NewLoginEmailBox.Text = "";
|
||||
var user = new Model.NewUser(username, password, email);
|
||||
SQLite.SaveUser(user);
|
||||
|
||||
Close();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user