示例#1
0
        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";
            string filename = "";
            filename += Locker.FileName;
            this.file_to_lock = filename;
            ChosenFile.Text = filename;
            SocketClient sock_obj = new SocketClient();
            this.sock_obj = sock_obj;
            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;
        }
示例#2
0
        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;

                }

            }
        }
示例#3
0
        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);
                }
                this.sock_obj.CloseClient();
                this.sock_obj = null;

                //if receives true then send the user to the next gui.
                if (message == "Signed in")
                {
                    string user_info = this.my_uid + "#" + this.firstname + "#" + this.lastname;
                    AdminSaveFile form = new AdminSaveFile(user_info);
                    form.Show();
                }
                else
                {

                    MessageBox.Show("incorrect password or username");
                    this.Show();
                }

            }
        }
示例#4
0
        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;
        }
示例#5
0
        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;
        }
示例#6
0
        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;
        }
示例#7
0
 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();
 }
示例#8
0
        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;
        }