removed hashing and saving to sql from view and moved it to appcontroller
This commit is contained in:
parent
7bf89dfeb8
commit
8fe00e3aca
@ -1,6 +1,13 @@
|
|||||||
namespace Project.Controller;
|
using Project.Persistence;
|
||||||
|
using Project.Model;
|
||||||
|
namespace Project.Controller;
|
||||||
|
|
||||||
public class AppController
|
public class AppController
|
||||||
{
|
{
|
||||||
|
public static void NewLoginSave(string username, string password, string email)
|
||||||
|
{
|
||||||
|
string hashedPassword = ShaHash.HashPassword(password);
|
||||||
|
var user = new Model.NewUser(username, hashedPassword, email);
|
||||||
|
SQLite.SaveUser(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,11 +11,11 @@ public static class ShaHash
|
|||||||
// convert string to byte array and hash
|
// convert string to byte array and hash
|
||||||
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(password));
|
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(password));
|
||||||
|
|
||||||
// Byte-Array als Hex-String formatieren
|
// convert byte array to hex-string - x2 = hex format
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
foreach (var b in bytes)
|
foreach (var b in bytes)
|
||||||
{
|
{
|
||||||
builder.Append(b.ToString("x2")); // x2 = hex format
|
builder.Append(b.ToString("x2"));
|
||||||
}
|
}
|
||||||
return builder.ToString();
|
return builder.ToString();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,10 +26,8 @@ public partial class NewLogin : Window
|
|||||||
string username = NewLoginUsernameBox.Text?.Trim();
|
string username = NewLoginUsernameBox.Text?.Trim();
|
||||||
string password = NewLoginPasswordBox.Text?.Trim();
|
string password = NewLoginPasswordBox.Text?.Trim();
|
||||||
string email = NewLoginEmailBox.Text?.Trim();
|
string email = NewLoginEmailBox.Text?.Trim();
|
||||||
string hashedPassword = ShaHash.HashPassword(password);
|
//give strings to appcontroller and keep working on them there
|
||||||
var user = new Model.NewUser(username, hashedPassword, email);
|
AppController.NewLoginSave(username, password, email);
|
||||||
SQLite.SaveUser(user);
|
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user