complete login function and login window also add attached properties and helper classes for securestring
This commit is contained in:
@@ -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 = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user