private void btnLogin_Click(object sender, EventArgs e) { if(Directory.Exists(CurrentPath + Database + txtUserName.Text) == true) { //All is good } else { Console.WriteLine("Database corrupted?"); MessageBox.Show("The database is corrupted, please remove the current user using the Administrator account and re-create it.", "Error"); return; } bool matchFound = false; UserNamePath myLoginUser = new UserNamePath(); foreach(UserNamePath testUser in UserNamePathList) { Console.WriteLine(testUser.Name); if(txtUserName.Text == testUser.Name) { matchFound = true; myLoginUser = testUser; Console.WriteLine(matchFound.ToString()); break; } else { matchFound = false; } } if(matchFound == true) { bool successLogin; successLogin = DecryptFile(myLoginUser.Path, CurrentPath + "\\currentload.db", txtPassword.Text); if(successLogin == true) { currentPassword = txtPassword.Text; String[] fileList; fileList = Directory.GetFiles(CurrentPath + Database + txtUserName.Text, "*.db"); //Decrypt all user tenants foreach(string fileName in fileList) { string tenantName; tenantName = Path.GetFileNameWithoutExtension(fileName); DecryptFile(fileName, CurrentPath + Database + currentLoad + tenantName + ".db", currentPassword); } SuccessLogin(); } else { MessageBox.Show("Incorrect password!", "Warning"); txtPassword.Focus(); } } else if(matchFound == false) { MessageBox.Show("The user " + txtUserName.Text + " does not exist.", "Error"); } }
private void LoadUser(String UserName, String FilePath) { UserNamePath loadUser = new UserNamePath(); loadUser.Name = UserName; loadUser.Path = FilePath; UserNamePathList.Add(loadUser); }
private void btnT2Remove_Click(object sender, EventArgs e) { int popIndex; popIndex = cbT2Users.SelectedIndex; UserNamePath popUser = new UserNamePath(); popUser = UserNamePathList[popIndex]; if (popUser.Name == "Administrator") { MessageBox.Show("Invalid action.", "Error"); return; } Console.WriteLine("Deleting user {0}.", popUser.Name); UserNamePathList.RemoveAt(popIndex); if(System.IO.File.Exists(popUser.Path) == true) { System.IO.File.Delete(popUser.Path); string[] fileList; fileList = Directory.GetFiles(CurrentPath + Database + popUser.Name); foreach (string fileName in fileList) { System.IO.File.Delete(fileName); } Directory.Delete(CurrentPath + Database + popUser.Name); } else { Console.WriteLine("No user file to delete?"); return; } populateUsers(); }