private void browse2lock_Click(object sender, EventArgs e) { OpenFileDialog Locker = new OpenFileDialog(); namesender.Enabled = true; browse2lock.Enabled = false; Locker.ShowDialog(); Locker.InitialDirectory = @"C:\"; Locker.Title = "Browse Files"; this.file_to_lock = Locker.FileName; ChosenFile.Text = Locker.FileName; this.sock_obj = new SocketClient(); this.sock_obj.StartClient(); this.sock_obj.Send("Lock"); string user_info_string = this.sock_obj.Recv(); // user_info_string = uid@fname@lname@uname@ph#..... string[] users = user_info_string.Split('#'); // Shutdown the painting of the ListBox as items are added. UserData.BeginUpdate(); // Loop through and add items to the listbox foreach (string user_string in users) { if (user_string != "") { if (!(this.my_uid == user_string.Split('@')[0])) { string user_data = user_string.Split('@')[1] + " " + user_string.Split('@')[2] + " " + user_string.Split('@')[0]; UserData.Items.Add(user_data); } } } // Allow the ListBox to repaint and display the new items. UserData.EndUpdate(); UserData.Show(); namesender.Enabled = true; }
private void UserSignIn(string username, string password) { if (username == "") { MessageBox.Show("Please enter username"); this.Show(); } else if (password == "") { MessageBox.Show("Please enter password"); this.Show(); } else { string hashed_password = sha256(password); //send username and password to python and checks if correct string info = "login#" + username + "#" + hashed_password; SocketClient sock_obj = new SocketClient(); this.sock_obj = sock_obj; this.sock_obj.StartClient(); this.sock_obj.Send(info); string message_to_split = this.sock_obj.Recv(); string message = message_to_split.Split('#')[0]; if (message_to_split.Split('#')[1] != "0") { this.my_uid = message_to_split.Split('#')[2]; this.firstname = message_to_split.Split('#')[1]; this.lastname = message_to_split.Split('#')[3]; //MessageBox.Show(my_uid + firstname + lastname); } //if receives true then send the user to the next gui. if (message == "Signed in") { this.sock_obj.Send("ok"); string available_files = this.sock_obj.Recv(); string user_info = this.my_uid + "$" + this.firstname + "$" + this.lastname + "$" + available_files; SaveFile form = new SaveFile(user_info); form.Show(); } else if (message == "Signed in, admin") { this.sock_obj.Send("ok"); string available_files = this.sock_obj.Recv(); string user_info = this.my_uid + "$" + this.firstname + "$" + this.lastname + "$" + available_files; AdminSaveFile form = new AdminSaveFile(user_info); form.Show(); } else { MessageBox.Show("Incorrect password or username"); this.Show(); } this.sock_obj.CloseClient(); this.sock_obj = null; } }
private void DownloadButton_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); MessageBox.Show("Please choose a download location"); folderBrowserDialog.ShowDialog(); string folder_location = folderBrowserDialog.SelectedPath; string file_to_download = ""; DownloadableBox.Enabled = false; for (int i = 0; i < DownloadableBox.Items.Count; i++) if (DownloadableBox.GetItemCheckState(i) == CheckState.Checked) { file_to_download = DownloadableBox.Items[i].ToString(); } if (!(file_to_download == "")) { this.sock_obj = new SocketClient(); this.sock_obj.StartClient(); this.sock_obj.Send("Download#" + file_to_download + "#" + this.my_uid + "#" + folder_location); string ack = this.sock_obj.Recv(); MessageBox.Show(ack); } else MessageBox.Show("Please choose a file to download"); }
private void FileChooser_Click(object sender, EventArgs e) { OpenFileDialog Uploader = new OpenFileDialog(); Uploader.ShowDialog(); Uploader.InitialDirectory = @"C:\"; Uploader.Title = "Choose file to upload"; this.file_to_upload = Uploader.FileName; MessageBox.Show(this.my_uid); string file_information = "Upload#" + this.file_to_upload + "#" + this.my_uid; SocketClient sock_obj = new SocketClient(); this.sock_obj = sock_obj; this.sock_obj.StartClient(); this.sock_obj.Send(file_information); string ack = this.sock_obj.Recv(); MessageBox.Show(ack); }
private void browse2unlock_Click_1(object sender, EventArgs e) { OpenFileDialog Unlocker = new OpenFileDialog(); Unlocker.ShowDialog(); Unlocker.InitialDirectory = @"C:\"; Unlocker.Title = "Browse Files to Unlock"; string file_to_unlock = Unlocker.FileName; string uid = this.my_uid; // need to get the current user uid string information_string = "Unlock#" + uid + "#" + file_to_unlock; SocketClient sock_obj = new SocketClient(); this.sock_obj = sock_obj; this.sock_obj.StartClient(); this.sock_obj.Send(information_string); string message = this.sock_obj.Recv(); if (message == "File Unlocked" || message == "File unlocked, user can only read the file") { MessageBox.Show(message); } else if (message == "The specified user is not allowed to open the file") { MessageBox.Show(message); } else if (message == "path error, can only unlock .cb files") { MessageBox.Show(message); } this.sock_obj.CloseClient(); this.sock_obj = null; }
private void continue_lock() { string ack = ""; string message = this.to_send; if (this.sock_obj != null) { this.sock_obj.Send(message); try { ack = this.sock_obj.Recv(); } catch { ack = "there was an error, please try again"; } MessageBox.Show(ack); this.sock_obj.CloseClient(); this.sock_obj = null; UserData.Items.Clear(); browse2lock.Enabled = true; } else MessageBox.Show("there was an error, please try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
private void UserChanges(string what_to_change, string new_item) { if (UserDatachange.Items.Count == 0) MessageBox.Show("Please choose a user"); if (whattochange.Items.Count == 0) MessageBox.Show("Please pick what you want to change for this user..."); string user_uid = UserDatachange.SelectedItem.ToString().Split(' ')[2]; string information = ""; if (what_to_change == "Last Name") { information = "Change#lname#" + user_uid + "#" + new_item; } else if (what_to_change == "First Name") { information = "Change#fname#" + user_uid + "#" + new_item; } else if (what_to_change == "Password") { Confirm.Enabled = true; newitem.PasswordChar = '●'; string pattern = @"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{8,15}$"; if (!Regex.IsMatch(new_item, pattern)) { MessageBox.Show("Password must be between 8-15 characters and must contain at least one uppercase letter, one lowercase letter and one number"); } else if (new_item != Confirm.Text) { MessageBox.Show("Passwords don't match"); } else { information = "Change#password#" + user_uid + "#" + sha256(new_item); } } this.sock_obj.Send(information); MessageBox.Show(this.sock_obj.Recv()); this.sock_obj.CloseClient(); this.sock_obj = null; }
private void Submit_Click(object sender, RoutedEventArgs e) { try { ClientSocket.Connect(ipEnd); if (ClientSocket.Connected) { this.client = new SocketClient(ClientSocket); } } catch (SocketException E) { MessageBox.Show("Connection" + E.Message); } if (this.client.Login(BoxLogin.Text, BoxPassword.Text)) { Login.Visibility = System.Windows.Visibility.Hidden; Menu.Visibility = System.Windows.Visibility.Visible; Brute.Visibility = System.Windows.Visibility.Visible; BruteBonus.Visibility = System.Windows.Visibility.Visible; this.client.GetBrute(BoxLogin.Text); Brute.BruteImageControl = "MyBruteImg.jpg"; Brute.NameTitleControl = this.client.MyBrute.Name; Brute.StatBruteControl = this.StatBruteMaker(this.client.MyBrute); BruteBonus.SetBonusImage = this.BonusListMaker(this.client.MyBrute,"BruteBonus"); } else { MessageBox.Show("Fail Connection"); } }
private void UserButton_Click(object sender, EventArgs e) { SocketClient sock_obj = new SocketClient(); this.sock_obj = sock_obj; this.sock_obj.StartClient(); this.sock_obj.Send("Delete#"); string user_info_string = this.sock_obj.Recv(); // user_info_string = uid@fname@lname@uname#..... string[] users = user_info_string.Split('#'); // Shutdown the painting of the ListBox as items are added. UserDatadel.BeginUpdate(); // Loop through and add items to the listbox foreach (string user_string in users) { if (!(this.my_uid == user_string.Split('@')[0])) { string user_data = user_string.Split('@')[1] + " " + user_string.Split('@')[2] + " " + user_string.Split('@')[0]; UserDatadel.Items.Add(user_data); } } // Allow the ListBox to repaint and display the new items. UserDatadel.EndUpdate(); UserDatadel.Show(); DeleteUser.Visible = true; }
private void Register(string firstname, string lastname, string username, string password, string confirmPass) { string pattern = @"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{8,15}$"; //asks the database if the username exists already if (password != confirmPass) { MessageBox.Show("Passwords do not match"); } else if (!Regex.IsMatch(password, pattern)) { MessageBox.Show("Password must be between 8-15 characters and must contain at least one uppercase letter, one lowercase letter and one number"); } //Password must be at least 8 characters long else if (password.Length < 8) { MessageBox.Show("Password must be at least 8 characters long"); } else if (username == null || username.Length < 2 || username.Length > 15) { MessageBox.Show("Username missing or too short"); } else if (firstname == null || firstname.Length < 2) { MessageBox.Show("First name missing or too short"); } else if (lastname == null || lastname.Length < 2) { MessageBox.Show("Last name missing or too short"); } else { this.Hide(); Random rnd = new Random(); int uid = rnd.Next(10000000, 99999999); string UID = uid.ToString(); string hashed_password = sha256(password); string information_string = "register#" + UID + "#" + firstname + "#" + lastname + "#" + username + "#" + hashed_password; //send python all the information for registration SocketClient sock_obj = new SocketClient(); this.sock_obj = sock_obj; this.sock_obj.StartClient(); this.sock_obj.Send(information_string); string message = this.sock_obj.Recv(); if (message == "Signed up") { MessageBox.Show("User Signed Up"); this.sock_obj.CloseClient(); this.sock_obj = null; this.Show(); } else if (message == "username exists") { MessageBox.Show("Username already exists"); this.Show(); this.sock_obj.CloseClient(); this.sock_obj = null; } } }
private void DeleteUser_Click(object sender, EventArgs e) { UserDatadel.Enabled = false; for (int i = 0; i < UserDatadel.Items.Count; i++) if (UserDatadel.GetItemCheckState(i) == CheckState.Checked) { this.uid_list.Add(UserDatadel.Items[i].ToString().Split(' ')[2]); } string uid_str = ""; foreach (string uid in this.uid_list) { uid_str += uid; } string user_to_del = uid_str; MessageBox.Show(user_to_del); this.sock_obj.Send(user_to_del); MessageBox.Show(this.sock_obj.Recv()); this.sock_obj.CloseClient(); this.sock_obj = null; }
private void continue_lock() { string message = this.to_send; this.sock_obj.Send(message); string ack = this.sock_obj.Recv(); MessageBox.Show(ack); this.sock_obj.CloseClient(); this.sock_obj = null; namesender.Enabled = false; browse2lock.Enabled = true; UserData.Enabled = true; ChosenFile.Text = ""; UserData.ClearSelected(); }
private void browse2unlock_Click_1(object sender, EventArgs e) { OpenFileDialog Unlocker = new OpenFileDialog(); Unlocker.ShowDialog(); Unlocker.InitialDirectory = @"C:\"; Unlocker.Title = "Browse Files to Unlock"; string file_to_unlock = Unlocker.FileName; string uid = this.my_uid; // need to get the current user uid string information_string = "Unlock#" + uid + "#" + file_to_unlock; SocketClient sock_obj = new SocketClient(); this.sock_obj = sock_obj; this.sock_obj.StartClient(); this.sock_obj.Send(information_string); string message = this.sock_obj.Recv(); MessageBox.Show(message); this.sock_obj.CloseClient(); this.sock_obj = null; }