/** * Default constructor * It will intialize the listBox and add the list to this box. * Used for Part 2 */ public LoginForm() { InitializeComponent(); this.listUserBox.SelectionMode = SelectionMode.One; ReadWriteFiles.ReadAccountFile(pathFileToRead); AddToListBox(); }
public LoginManyForm() { InitializeComponent(); ReadWriteFiles.ReadAccountFile(Model.emailAccountFile); UpdateUserName("svp" + --Model.Count); RandomizeGroupBox(); }
/* * Practice button handler * It is used to call the practice form to practice the password as many time as they want * It will be refreshed by the Refresh button, so the password is always up to date. No need to close the form to refresh */ private void practiceBtn_Click(object sender, EventArgs e) { if (!String.IsNullOrWhiteSpace(this.passwordTxtBox.Text)) { Logger.Log("User [" + this.userLb.Text + "] used practice form for password [" + Model.Password + "] and keyword [" + Model.KeyWord + "]"); //Use DisplayForm function to open only 1 form ReadWriteFiles.DisplayForm(ref practiceForm); } }
/* * Hint button handler * It will call the Hint form with the keyword for user to memorize the password */ private void hintBtn_Click(object sender, EventArgs e) { if (!String.IsNullOrWhiteSpace(this.passwordTxtBox.Text)) { Logger.Log("User [" + this.userLb.Text + "] used hint button"); //Use DisplayForm function to open only 1 form ReadWriteFiles.DisplayForm(ref hintForm); } }
//Alternative log to emphasize the username public static void Log(string user, string msg) { string thisDay = DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"); string logUser = "******" + user + " --------------"; ReadWriteFiles.WriteToFile(Model.logFileName, logUser); string logTime = "[" + thisDay + "]" + " " + msg; ReadWriteFiles.WriteToFile(Model.logFileName, logTime); }
//Default constructor for part 2 public GenerateForm() { InitializeComponent(); InitializeToolTip(); //Read from the account file and save all available accounts to Data/Model ReadWriteFiles.ReadAccountFile(pathFileToSave); UpdateUserName("svp" + Model.Count); UpdatePassword(String.Empty); }
public GenerateManyForm() { InitializeComponent(); ReadWriteFiles.ReadAccountFile(Model.emailAccountFile); UpdateUserName("svp" + Model.Count); //Only enable the first button to force user to create all 3 password in ordered this.createEmailPassBtn.Enabled = true; this.createShopPassBtn.Enabled = false; this.createBankPassBtn.Enabled = false; }
/** * Constructor * Remove the list box in GUI, add user and status lables * Used for Part 3 */ public LoginForm(LoginManyForm _form, string userName, string WhatPurpose, string ReadThisFile, int _attempt = 0) { InitializeComponent(); //Read the path file and save the data to Data/Model this.pathFileToRead = ReadThisFile; ReadWriteFiles.ReadAccountFile(pathFileToRead); this.titleLb.Text = "LOGIN FORM for " + WhatPurpose; this.userNameTitleLb.Text = "Username: "******"Microsoft Sans Serif", 8.25f), Text = userName, AutoSize = true, Location = new Point(70, 39), ForeColor = Color.NavajoWhite, BackColor = Color.Transparent, }; this.user = userName; this.userLb.Show(); this.Controls.Add(this.userLb); //Initialize status label that displays username and add it to Controls this.statusLb = new Label { Font = new Font("Microsoft Sans Serif", 10f), Text = "(" + attempt + " attempts)", AutoSize = true, Location = new Point(12, 72), ForeColor = Color.NavajoWhite, BackColor = Color.Transparent, }; this.statusLb.Show(); this.Controls.Add(this.statusLb); //Logging Logger.Log(whatPurpose, 2); }
/** * Read the file then add to Model.Accounts list */ public static void ReadAccountFile(string chooseAccountFileName) { string countSavedUser = ""; Model.EraseAccounts(); List <String> lines = ReadWriteFiles.ReadFromFile(chooseAccountFileName); if (lines.Count != 0) { Console.WriteLine(lines); foreach (string aLine in lines) { string _user = aLine.Split(',').First(); string _pass = aLine.Split(',').ElementAt(1); string _key = aLine.Split(',').Last(); Model.AddToAccounts(_user, _pass); countSavedUser = _user; } Model.Count = Convert.ToInt32(Regex.Match(countSavedUser, @"\d+").Value) + 1; } }
/**------------------HELPER FUNCTION-------------------*/ //Handler adding new account to the database private void addNewAccount() { foreach (string key in accounts.Keys) { if (String.Equals(key, this.userLb.Text)) { Logger.Log("This user already had password"); return; } } //Add the username with this password to the Dictionary accounts accounts.Add(this.userLb.Text, this.passwordTxtBox.Text); //Write the password with this username to the data file string msg = Model.UserName + "," + Model.Password + "," + Model.KeyWord; ReadWriteFiles.WriteToFile(pathFileToSave, msg); Logger.Log("User [" + Model.UserName + "] - password [" + Model.Password + "] - keyword [" + Model.KeyWord + "] has been added to the file at [" + this.pathFileToSave + "]"); Logger.Log("Completed [" + whatPurpose + "] form"); this.lockButton = true; }
//Main log function with 5 levels public static void Log(string msg, int isNewLine = 0) { string logTime = null; if (isNewLine == 0) { string thisDay = DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"); logTime = "[" + thisDay + "]" + " " + msg; } else if (isNewLine == 1) { string thisDay = DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"); logTime = "\n[" + thisDay + "]" + " " + msg; } else if (isNewLine == 2) { string thisDay = DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"); logTime = "\n---------[" + msg + "]---------"; } else if (isNewLine == 3) { string thisDay = DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"); logTime = "-----------------------" + "\n-----------------------\n[" + thisDay + "]" + " " + msg; } else if (isNewLine == 4) { string thisDay = DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"); logTime = "\n\n=====================================================================\n" + "=====================================================================\n" + "==================NEW SECTION [" + thisDay + "]=================\n" + "=====================================================================\n" + "=====================================================================\n"; } ReadWriteFiles.WriteToFile(Model.logFileName, logTime); }
//Create password button for the part 2 private void createPasswordBtn_Click(object sender, EventArgs e) { Logger.Log("User chose to create single password (part 2)", 3); ReadWriteFiles.DisplayForm(ref generateForm); }
//Get the log file location and open it using Notepad public static void DisplayLogFile() { ReadWriteFiles.DisplayFile(Model.logFileName); }
//Create password button for the part 3 private void createMassBtn_Click(object sender, EventArgs e) { Logger.Log("User chose to create 3 passwords (part 3)", 3); ReadWriteFiles.DisplayForm(ref generateManyForm); }
//Login button for the part 3 private void loginMassBtn_Click(object sender, EventArgs e) { Logger.Log("User chose to login 3 passwords (part 3)", 3); ReadWriteFiles.DisplayForm(ref loginManyForm); }
//ToolStripMenu for displaying shopping file private void displayShoppingAccountsToolStripMenuItem_Click(object sender, EventArgs e) { ReadWriteFiles.DisplayFile(Model.shoppingAccountFile); }
//Login button for the part 2 private void loginBtn_Click(object sender, EventArgs e) { Logger.Log("User chose to login single password (part 2)", 3); ReadWriteFiles.DisplayForm <LoginForm>(ref loginForm); }
//Display account file using notepad private void displayAccountsToolStripMenuItem_Click(object sender, EventArgs e) { ReadWriteFiles.DisplayFile(pathFileToSave); }