private bool PasswordInputIsValid() { if (FieldIsEmpty(screen.PasswordTextBox, "Password")) { screen.PasswordValidatorLabel.Text = "Enter password"; return(false); } if (FieldIsEmpty(screen.UsernameTextBox, "Username")) { return(false); } string username = screen.UsernameTextBox.Text.Trim(); string password = screen.PasswordTextBox.Text.Trim(); bool passWordMatches = UserFileUtil.UsernamePasswordMatches(username, password); if (!passWordMatches) { if (screen.UsernameValidatorLabel.Text.Length == 0) { screen.PasswordValidatorLabel.Text = "Password is wrong"; } else { screen.PasswordValidatorLabel.Text = "Username or password is wrong"; } return(false); } screen.PasswordValidatorLabel.Text = ""; return(true); }
private bool UsernameInputIsValid() { if (FieldIsEmpty(screen.UsernameTextBox, "Username")) { screen.UsernameValidatorLabel.Text = "Enter valid username"; return(false); } if (FieldIsEmpty(screen.PasswordTextBox, "Password")) { return(false); } string username = screen.UsernameTextBox.Text.Trim(); bool userExists = UserFileUtil.UsernameExists(username); if (!userExists) { screen.UsernameValidatorLabel.Text = "Couldn't find your username"; return(false); } screen.UsernameValidatorLabel.Text = ""; return(true); }
private bool UsernameInputIsValid() { string username = screen.RUsernameTextBox.Text.Trim(); if (username.Length == 0) { screen.RegisterUserNameValidatorLabel.Text = "Enter username"; return(false); } if (username.Where(Char.IsLetter).Count() == 0) { screen.RegisterUserNameValidatorLabel.Text = "Wrong username format"; return(false); } if (username.Equals("Username")) { screen.RegisterUserNameValidatorLabel.Text = "Enter valid username"; return(false); } bool userExists = UserFileUtil.UsernameExists(username); if (userExists) { screen.RegisterUserNameValidatorLabel.Text = "This username is already registered"; return(false); } screen.RegisterUserNameValidatorLabel.Text = ""; return(true); }
// written for testing purpose public static void PrintAllUserData() { List <string> lines = UserFileUtil.GetAllUserData(); foreach (string line in lines) { Console.WriteLine(line); } }
private void StartLoginProcess() { bool canAccess = loginValidator.AreAllInputsValid(); if (canAccess) { string userData = UserFileUtil.GetUserData(userNameTextBox.Text.Trim(), false); UserFileUtil.WriteCurrentUserDataToFile(userData); StartSystem(); } }
private void StartRegistrationProcess() { bool canAccess = registrationValidator.AreAllInputsValid(); if (canAccess) { List <string> allUserData = UserFileUtil.GetAllUserData(); AddNewUser(allUserData); string encryptedData = UserFileUtil.EncryptAllDataInList(allUserData); UserFileUtil.WriteEncryptedDataToFile(encryptedData); string currentUserData = UserFileUtil .GetUserData(RUsernameTextBox.Text.Trim(), false); UserFileUtil.WriteCurrentUserDataToFile(currentUserData); StartSystem(); } }
private void ClearUserData() { UserFileUtil.ClearCurrentUserData(); }