Пример #1
0
        private void ButtonLogIn_Click(object sender, EventArgs e)
        {
            //-----select path and create list-----
            string path      = @"C:\Temp\Users.txt";
            var    UsersList = new List <string>();

            //-----Try to read users from file-----
            try
            {
                UsersList = new List <string>(File.ReadAllLines(path));
            }
            catch (Exception)
            {
                MessageBox.Show("Oops. Something went wrong");
            }
            //-----Set number og users read to 0-----
            int Usrcount = 0;

            //-----Go throw all users and see if they match the login info-----
            foreach (String item in UsersList)
            {
                //-----Construct seperator-----
                string   password  = item;
                string[] seperator = { ", " };
                Int32    count     = 2;
                string[] strlist   = password.Split(seperator, count, StringSplitOptions.RemoveEmptyEntries);

                //-----Add one to usrcount becuase one user is now being read-----
                Usrcount = Usrcount + 1;

                //-----Chek if username is correct else send error-----
                if (strlist[0] == textBoxUsername.Text)
                {
                    //-----Hash the password from login and varify password if worong send error-----
                    var result = SecureHasher.Verify(textBoxPassword.Text, strlist[1]);
                    if (result.Equals(false))
                    {
                        MessageBox.Show("Wrong Username or password");
                    }
                    else
                    {
                        Form Login = new LogIn();
                        //-----Ask if you want to skip Facedetection-----
                        DialogResult MBResult = MessageBox.Show("Want to skip Facedetection?", "Skip", MessageBoxButtons.YesNo);
                        if (MBResult.Equals(DialogResult.Yes))
                        {
                            username = textBoxUsername.Text;
                            //-----Mount the encrypted file from server on computer-----
                            Mount();
                            //-----Open home (file explorer) and send username to home form and close login-----
                            Form Home = new Home(username);
                            Home.Show();
                        }
                        else
                        {
                            //-----open FaceDetection and close login-----
                            Form Face = new FaceDetection(username);
                            Face.Show();
                        }
                    }
                }

                //-----If no more users to go throw send error-----
                else if (UsersList.Count() == Usrcount)
                {
                    MessageBox.Show("Wrong Username or password");
                }
            }
        }
Пример #2
0
        private void ButtonNewUser_Click(object sender, EventArgs e)
        {
            //-----Try to create new user-----
            try
            {
                //-----Ask user if they want to create new user-----
                DialogResult result = MessageBox.Show("Do you want to create a new account?", "User Creation", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    //-----Get new account password and username-----
                    string UserNameInput = Interaction.InputBox("Please Select Your Username:"******"Username Selection");
                    string PasswordInput = Interaction.InputBox("Please Select Your Password:"******"Password Selection");

                    //-----Chek if username and password is at least 5 long else send error-----
                    if (UserNameInput == "" && UserNameInput.Length > 5 && PasswordInput == "" && PasswordInput.Length > 5)
                    {
                        MessageBox.Show("No Username or Username too short");
                    }

                    //-----Chek if data is correct-----
                    DialogResult ConResult = MessageBox.Show("Confirmation of information:\n Username: "******"\n Password: "******"", "Confirmation", MessageBoxButtons.YesNo);

                    //-----Create user-----
                    if (ConResult == DialogResult.Yes)
                    {
                        //-----Declare path and file name and chek if it allready exists else create file-----
                        string path = @"C:\Temp\Users.txt";
                        if (!File.Existqs(path))
                        {
                            FileStream NewFile = File.Create(path);
                            NewFile.Close();
                        }
                        else
                        {
                            //-----If file exists then hash pasword and save user to file-----
                            var        UsersList  = new List <string>(File.ReadAllLines(path));
                            TextWriter FileWriter = new StreamWriter(path);
                            foreach (String item in UsersList)
                            {
                                FileWriter.WriteLine(item);
                            }
                            var hash = SecureHasher.Hash(PasswordInput);
                            FileWriter.WriteLine(UserNameInput + ", " + hash);
                            FileWriter.Flush();
                            FileWriter.Close();
                        }
                        MessageBox.Show("User will be created. This may take a while.");
                        //-----Create encrypted file on the server-----
                        MessageBox.Show(string.Format(@"""{0}\VeraCrypt Format.exe"" /silent /create ""{1}\{2}"" /hash sha512 /encryption aes /size 200M /filesystem fat /dynamic /password ""{3}""", veracryptFolder, serverAddress, UserNameInput, PasswordInput));
                        CmdExecute(string.Format(@"""{0}\VeraCrypt Format.exe"" /silent /create ""{1}\{2}"" /hash sha512 /encryption aes /size 200M /filesystem fat /dynamic /password ""{3}""", veracryptFolder, serverAddress, UserNameInput, PasswordInput));
                        //-----------------------------
                        MessageBox.Show("User Created");
                    }
                }
            }
            //-----If something goes worng send error report-----
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }