complete login function and login window also add attached properties and helper classes for securestring

This commit is contained in:
Rene Schwarz
2021-04-03 23:52:00 +02:00
parent 077f622115
commit a42f756d78
32 changed files with 377 additions and 37 deletions

View File

@@ -1,15 +1,62 @@
using System;
using System.Collections.Generic;
using System.Security;
using System.Text;
using System.Windows.Input;
namespace Server_Dashboard {
class LoginViewModel {
private string password;
class LoginViewModel : BaseViewModel {
public string Password {
get { return password; }
set { password = value; }
private string username;
public string Username {
get { return username; }
set {
if (username != value)
username = value;
OnPropertyChanged(nameof(username));
}
}
private string errorText;
public string ErrorText {
get { return errorText; }
set {
if (errorText != value)
errorText = value;
OnPropertyChanged(nameof(errorText));
}
}
public LoginViewModel() {
LoginCommand = new RelayCommand(Login);
}
public ICommand LoginCommand { get; set; }
private void Login(object parameter) {
if (!String.IsNullOrWhiteSpace(Username) && !String.IsNullOrWhiteSpace((parameter as IHavePassword).SecurePassword.Unsecure())) {
if (DatabaseHandler.CheckLogin(Username, (parameter as IHavePassword).SecurePassword.Unsecure())) {
Console.WriteLine();
} else {
ErrorText = "Username or password is wrong.";
return;
}
} else if (String.IsNullOrWhiteSpace(Username) && String.IsNullOrWhiteSpace((parameter as IHavePassword).SecurePassword.Unsecure())) {
ErrorText = "Please provide a username and password";
return;
}
if (String.IsNullOrWhiteSpace(Username)) {
ErrorText = "Username cannot be empty.";
return;
}
if (String.IsNullOrWhiteSpace((parameter as IHavePassword).SecurePassword.Unsecure())) {
ErrorText = "Password cannot be empty.";
return;
}
ErrorText = "";
}
}
}