/// <summary> /// For current users that want to login into there account /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uxLoginButton_Click(object sender, EventArgs e) { string username = uxLoginUsernameBox.Text; string password = uxLoginPasswordBox.Text; byte[] p = File.ReadAllBytes("User_Manafest"); string temp = Encrypter.Decrypt(p, 5); string[] arr = temp.Split('\n'); bool found = false; for (int i = 0; i < arr.Length - 1; i++) { if (arr[i].Length > 5) { string[] info = arr[i].Split(','); if (info[0] == username && info[1] == password) { Username = username; found = true; this.DialogResult = DialogResult.OK; this.Close(); } } } if (!found) { MessageBox.Show("Username and password not found."); } }
/// <summary> /// For new users who want to create an account. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uxSignUpButton_Click(object sender, EventArgs e) { //Create users in text file database string username = uxSignUpNameBox.Text; string password = uxSignUpPasswordBox.Text; byte[] bytes = File.ReadAllBytes("User_Manafest"); if (username.Length > 2 && username.Length < 16) { if (checkPasswordReqirements(password)) { bool usernameCheck = true; string temp = Encrypter.Decrypt(bytes, 5); string[] arr = temp.Split('\n'); for (int i = 0; i < arr.Length - 1; i++) { string[] info = arr[i].Split(','); if (info[0] == username) { usernameCheck = false; } } if (usernameCheck) { string info = username + "," + password + "\n"; byte[] newBytes = Encrypter.Encrypt(info, 5); using (var stream = new FileStream("User_Manafest", FileMode.Append)) { stream.Write(newBytes, 0, newBytes.Length); } Username = username; this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("The username you entered is already taken."); } } else { MessageBox.Show("Invalid password. \nPassword must be at least 7 characters long and contain at least 1 uppercase letters.\nThe only other characters that are allowed are ! @ # $ ?"); } } else { MessageBox.Show("Username must be at least 3 characters long and at most 15 characters long."); } }
/// <summary> /// Reads in all a users data /// </summary> /// <param name="path">The file to read from</param> /// <param name="key">Key of the user whos data is being saved</param> /// <returns>A list with all the information read in</returns> private static List <string> readInData(string path, byte key) { byte[] bytes = File.ReadAllBytes(path); string temp = Encrypter.Decrypt(bytes, key); List <string> result = new List <string>(); string [] tempArray = temp.Split('\n'); for (int i = 0; i < tempArray.Length; i++) { if (tempArray[i].Length > 5) { result.Add(tempArray[i]); } } return(result); }