예제 #1
0
 private void FindKeyFile_Click(object sender, EventArgs e)
 {
     if (FileOP.SelectKeyFile())
     {
         KeyfileLocation.Text = FileOP.GetKeyFile();
     }
 }
예제 #2
0
        /// <summary>
        /// Decompresses a file using GZip decompression.
        /// </summary>
        /// <param name="inFile">Filepath of the file to be decompressed.</param>
        public static void Decompress(string inFile)
        {
            //Makes new FileInfo for the target file
            FileInfo fileToDecompress = new FileInfo(inFile);

            // Creates a FileStream containing the data from fileToDecompress
            using (FileStream originalFileStream = fileToDecompress.OpenRead()) {
                string currentFileName = fileToDecompress.FullName;
                string newFileName     = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length);

                // Creates the decompressed file stream
                using (FileStream decompressedFileStream = File.Create(newFileName)) {
                    // Creates the compression stream
                    using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress)) {
                        // Decompresses file
                        decompressionStream.CopyTo(decompressedFileStream);
                    }
                }

                // Updates FileOP to the decompressed file
                FileOP.LoadFile(FileOP.GetFile().Remove(FileOP.GetFile().Length - fileToDecompress.Extension.Length));
            }

            // Delete compressed file
            File.Delete(inFile);
        }
예제 #3
0
        /// <summary>
        /// Opens up the dialog for creating a new password file
        /// Returns true upon success and false upon premature closing.
        /// </summary>
        public static bool CreateFile()
        {
            Stream myStream;
            //default to creating a .csv file
            SaveFileDialog save = new SaveFileDialog {
                Filter = "CSV |*.csv",
                Title  = "Save password DB"
            };

            //opens up the file explorer dialog menu and determines if the result is the ok button
            if (save.ShowDialog() == DialogResult.OK)
            {
                //as long as the stream is not null load the file name and optionally print it for testing purposes
                if ((myStream = save.OpenFile()) != null)
                {
                    FileOP.LoadFile(save.FileName);
                    FileOP.PrintFileName();
                    myStream.Close();
                }
                //Write the first line of the file to the file.
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(save.FileName, true)) {
                    file.WriteLine("Expiration Date,Title,UserName,Password,URL,Notes");
                    file.Close();
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #4
0
 private void OkButton_Click(object sender, EventArgs e)
 {
     if ((PassEntry1.Text == PassEntry2.Text) && String.IsNullOrEmpty(PassEntry1.Text) == false && String.IsNullOrEmpty(PassEntry2.Text) == false)
     {
         if (KeyFileCheckBox.Checked)
         {
             if (FileOP.GetKeyFile() != "" && FileOP.GetKeyFile() != null && File.Exists(FileOP.GetKeyFile()))
             {
                 KeyFileLocationText.Text = FileOP.GetKeyFile();
                 Crypto.mPassTemp         = PassEntry1.Text;
                 CreatePrintPopUp();
             }
             else
             {
                 MessageBox.Show("Your key file is invalid. Please reselect your keyfile.", "File Error", MessageBoxButtons.OK);
             }
         }
         else
         {
             Crypto.mPassTemp = PassEntry1.Text;
             CreatePrintPopUp();
         }
     }
     else
     {
         string            message = "Your passwords do not match or the boxes are blank. Please try entering them again";
         string            title   = "Pass Keeper";
         MessageBoxButtons buttons = MessageBoxButtons.OK;
         _ = MessageBox.Show(message, title, buttons);
     }
 }
예제 #5
0
 /// <summary>
 /// Clears the local memory by clearing any bariables used in fileOP and crypto
 /// </summary>
 private void ClearMem()
 {
     FileOP.ClearKeyFile();
     FileOP.ClearFile();
     Crypto.mPassTemp = "";
     this.PerformRefresh(false);
 }
예제 #6
0
        /// <summary>
        /// Compresses a file using GZip compression.
        /// </summary>
        /// <param name="inFile">Filepath of the file to be compressed.</param>
        public static void Compress(string inFile)
        {
            //Makes new FileInfo for the target file
            FileInfo fileToCompress = new FileInfo(inFile);

            // Creates a File Stream containing the data in the fileToCompress
            using (FileStream originalFileStream = fileToCompress.OpenRead()) {
                // Check that the file is not hidden or already a .gz file
                if ((File.GetAttributes(fileToCompress.FullName) & FileAttributes.Hidden) != FileAttributes.Hidden & fileToCompress.Extension != ".gz")
                {
                    // Creates a File Stream for the compressed file
                    using (FileStream compressedFileStream = File.Create(fileToCompress.FullName + ".gz")) {
                        // Creates the compression stream
                        using (GZipStream compressionStream = new GZipStream(compressedFileStream, CompressionMode.Compress)) {
                            // Compresses file
                            originalFileStream.CopyTo(compressionStream);
                        }
                    }
                }
            }

            // Delete uncompressed file
            File.Delete(inFile);

            // Updates the file
            FileOP.LoadFile(FileOP.GetFile() + ".gz");
        }
예제 #7
0
 private void StegExport_Click(object sender, EventArgs e)
 {
     if (FileOP.GetFile() != "")
     {
         StegExport frm = new StegExport();
         frm.ShowDialog();
     }
 }
예제 #8
0
 /// <summary>
 /// Calls the save function when the user clicks the save file button.
 /// </summary>
 private void SaveButton_Click(object sender, EventArgs e)
 {
     if (FileOP.GetFile() != "")
     {
         DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1);
         UnlockFile();
         FileOP.WriteToFile(dataTable);
         LockFile();
     }
 }
        private void button1_Click(object sender, EventArgs e)
        {
            FileOP.SelectKeyFile();
            Crypto.EncryptFile(FileOP.GetFile(), FileOP.KeyFileToBits(FileOP.GetKeyFile()));
            FileOP.ClearKeyFile();
            MasterForm frm = new MasterForm();

            frm.Show();
            frm.PerformRefresh();
            this.Close();
        }
예제 #10
0
 private void EnterPasswordForFile_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!success)
     {
         FileOP.ClearFile();
         FileOP.ClearKeyFile();
     }
     else
     {
         success = false;
     }
 }
예제 #11
0
 private void PasswordOptions_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!success)
     {
         File.Delete(FileOP.GetFile());
         FileOP.ClearFile();
         FileOP.ClearKeyFile();
     }
     else
     {
         success = false;
     }
 }
예제 #12
0
 /// <summary>
 /// Function for when the form closes. Asks the consumer if they would like to save the file they currently have open
 /// </summary>
 private void MasterForm_FormClosing(Object sender, FormClosingEventArgs e)
 {
     if (FileOP.GetFile() != "")
     {
         if (MessageBox.Show("Would you like to save the current working file?", "Close Program", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1);
             UnlockFile();
             FileOP.WriteToFile(dataTable);
             LockFile();
         }
         ClearMem();
     }
 }
예제 #13
0
        /// <summary>
        /// Unlocks the current file
        /// </summary>
        private void UnlockFile()
        {
            if (FileOP.GetKeyFile().Length > 0)
            {
                Crypto.DecryptFile(FileOP.GetFile(), FileOP.KeyFileToBits(FileOP.GetKeyFile()));
                CryptoProgBar.Value = 16;
            }

            Crypto.DecryptFile(FileOP.GetFile(), Crypto.mPassTemp);
            CryptoProgBar.Value = 33;

            Compressor.Decompress(FileOP.GetFile());
            CryptoProgBar.Value = 50;
        }
예제 #14
0
 /// <summary>
 /// Lock and encrypt the currently open file.
 /// </summary>
 private void LockButton_Click(object sender, EventArgs e)
 {
     if (FileOP.GetFile() != "")
     {
         DialogResult savePrompt = MessageBox.Show("Would you like to save the current working file?", "Lock Current File", MessageBoxButtons.YesNo);
         if (savePrompt == DialogResult.Yes)
         {
             DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1);
             UnlockFile();
             FileOP.WriteToFile(dataTable);
             LockFile();
         }
         ClearMem();
     }
 }
예제 #15
0
 /// <summary>
 /// Sets the datagridviews datasource to be the datatable constructed by the readfile method.
 /// </summary>
 public void PerformRefresh(bool opened)
 {
     if (FileOP.GetFile() != "")
     {
         if (!opened)
         {
             UnlockFile();
         }
         dataGridView1.DataSource = FileOP.ReadFile();
         LockFile();
     }
     else
     {
         dataGridView1.DataSource = null;
     }
 }
예제 #16
0
 /// <summary>
 /// Locks the file when called
 /// </summary>
 private void LockFile()
 {
     //Compresses File
     Compressor.Compress(FileOP.GetFile());
     CryptoProgBar.Value = 66;
     //Encrypt the file with stored password
     Crypto.EncryptFile(FileOP.GetFile(), Crypto.mPassTemp);
     CryptoProgBar.Value = 83;
     //If a Keyfile was used to open the file, use it to encrypt the file when locking
     if (FileOP.GetKeyFile().Length > 0)
     {
         //Encrypt the file with the KeyFile
         Crypto.EncryptFile(FileOP.GetFile(), FileOP.KeyFileToBits(FileOP.GetKeyFile()));
         CryptoProgBar.Value = 100;
     }
     CryptoProgBar.Value = 0;
 }
예제 #17
0
        private void KeyFileLocationText_DragOver(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }

            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (files != null && files.Length != 0)
            {
                KeyFileLocationText.Text = files[0];
                FileOP.LoadKeyFile(KeyFileLocationText.Text);
            }
        }
예제 #18
0
 /// <summary>
 /// Opens the dialog for opening a file allows opening of .gz files
 /// </summary>
 public static bool SelectFile()
 {
     using (OpenFileDialog openFileDialog = new OpenFileDialog()) {
         openFileDialog.InitialDirectory = "c:\\";
         openFileDialog.Filter           = "gz file (*.gz)|*.gz";
         openFileDialog.RestoreDirectory = true;
         //if the result is ok load the file
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             //set the path of the file that is selected
             FileOP.LoadFile(openFileDialog.FileName);
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
        private void OkButton_Click(object sender, EventArgs e)
        {
            if ((PassEntry1.Text == PassEntry2.Text) && String.IsNullOrEmpty(PassEntry1.Text) == false && String.IsNullOrEmpty(PassEntry2.Text) == false)
            {
                if (KeyFileCheckBox.Checked)
                {
                    if (FileOP.GetKeyFile() != "" && FileOP.GetKeyFile() != null && File.Exists(FileOP.GetKeyFile()))
                    {
                        Compressor.Compress(FileOP.GetFile());
                        Crypto.EncryptFile(FileOP.GetFile(), PassEntry1.Text);
                        Crypto.EncryptFile(FileOP.GetFile(), FileOP.KeyFileToBits(FileOP.GetKeyFile()));
                        KeyFileLocationText.Text = FileOP.GetKeyFile();
                        FileOP.ClearKeyFile();

                        MasterPasswordPrintPopUp printPopUp = new MasterPasswordPrintPopUp(PassEntry1.Text);
                        printPopUp.ShowDialog();
                        FileOP.ClearFile();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Your key file is invalid. Please reselect your keyfile.", "File Error", MessageBoxButtons.OK);
                    }
                }
                else
                {
                    Compressor.Compress(FileOP.GetFile());
                    Crypto.EncryptFile(FileOP.GetFile(), PassEntry1.Text);

                    MasterPasswordPrintPopUp printPopUp = new MasterPasswordPrintPopUp(PassEntry1.Text);
                    printPopUp.ShowDialog();
                    FileOP.ClearFile();
                    this.Close();
                }
            }
            else
            {
                string            message = "Your passwords do not match or the boxes are blank. Please try entering them again";
                string            title   = "Pass Keeper";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                _ = MessageBox.Show(message, title, buttons);
            }
        }
예제 #20
0
 /// <summary>
 /// Opens the dialog for opening a file allows opening of all files to allow any file to be a key file
 /// </summary>
 public static bool SelectKeyFile()
 {
     using (OpenFileDialog openFileDialog = new OpenFileDialog()) {
         openFileDialog.InitialDirectory = "c:\\";
         openFileDialog.Filter           = "All files (*.*)|*.*";
         openFileDialog.FilterIndex      = 2;
         openFileDialog.RestoreDirectory = true;
         //if the result is ok load the file
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             //Get the path of specified file
             FileOP.LoadKeyFile(openFileDialog.FileName);
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
예제 #21
0
        /// <summary>
        /// Writes all the password entries to the CSV file.
        /// </summary>
        public static void WriteToFile(DataTable dataTable)
        {
            string origFilePath = GetFile();

            // Creation of temp file to rewrite file
            string tempFile = "temp_file.csv";

            using (FileStream fs = File.Create(tempFile)) { }

            // Write all of the password entries in the data table to the temp file
            using (StreamWriter writer = new StreamWriter(tempFile)) {
                using (CsvWriter csvWriter = new CsvWriter(writer, CultureInfo.InvariantCulture)) {
                    // Setting the map so that entries get written into the correct columns
                    csvWriter.Context.RegisterClassMap <PasswordEntryMap>();

                    // Creates a list for the password entries and adds the entries to it
                    List <PasswordEntry> passwordEntries = new List <PasswordEntry>()
                    {
                    };
                    foreach (DataRow row in dataTable.Rows)
                    {
                        PasswordEntry passwordEntry = new PasswordEntry(row["expiration date"].ToString(), row["title"].ToString(), row["username"].ToString(),
                                                                        row["password"].ToString(), row["url"].ToString(), row["notes"].ToString());
                        passwordEntries.Add(passwordEntry);
                    }

                    // Casting the password list to an IEnumerable
                    IEnumerable <PasswordEntry> enumData = passwordEntries;

                    // Write the entries to the CSV
                    csvWriter.WriteRecords(enumData);
                }
            }

            // Replace the original file with the temp file
            File.Delete(origFilePath);
            File.Move(tempFile, origFilePath);

            // Update the file currently being used by the program
            FileOP.LoadFile(origFilePath);
        }
예제 #22
0
 private void Confirm_Click(object sender, EventArgs e)
 {
     if (KeyfileLocation.TextLength > 0)
     {
         if (!Crypto.DecryptFile(FileOP.GetFile(), FileOP.KeyFileToBits(KeyfileLocation.Text)))
         {
             MessageBox.Show("Inncorrect Credentials. Please Try Again.", "Access Denied", MessageBoxButtons.OK);
             KeyfileLocation.ResetText();
         }
         else if (!Crypto.DecryptFile(FileOP.GetFile(), passwordEntry.Text))
         {
             Crypto.EncryptFile(FileOP.GetFile(), FileOP.KeyFileToBits(KeyfileLocation.Text));
             MessageBox.Show("Inncorrect Credentials. Please Try Again.", "Access Denied", MessageBoxButtons.OK);
             KeyfileLocation.ResetText();
         }
         else
         {
             FileOP.LoadKeyFile(KeyfileLocation.Text);
             Crypto.mPassTemp = passwordEntry.Text;
             Compressor.Decompress(FileOP.GetFile());
             TheParent.PerformRefresh(true);
             success = true;
             this.Close();
         }
     }
     else if (!Crypto.DecryptFile(FileOP.GetFile(), passwordEntry.Text))
     {
         MessageBox.Show("Inncorrect Credentials. Please Try Again.", "Access Denied", MessageBoxButtons.OK);
         KeyfileLocation.ResetText();
     }
     else
     {
         Crypto.mPassTemp = passwordEntry.Text;
         Compressor.Decompress(FileOP.GetFile());
         TheParent.PerformRefresh(true);
         success = true;
         this.Close();
     }
 }
예제 #23
0
 private void FindKeyFile_Click(object sender, EventArgs e)
 {
     FileOP.SelectKeyFile();
     KeyFileLocationText.Text = FileOP.GetKeyFile();
 }
예제 #24
0
        /// <summary>
        /// Displays a warning to the user that they are about to create a new file.
        /// </summary>
        private void DisplayNewFileWarning()
        {
            string            message = "Are you sure you wish to create a new password File?";
            string            title   = "Pass Keeper";
            MessageBoxButtons buttons = MessageBoxButtons.YesNo;

            //creates a dialog box with the message, title and button options
            DialogResult confirm = MessageBox.Show(message, title, buttons);

            //if they want to make a new file
            if (confirm == DialogResult.Yes)
            {
                if (FileOP.GetFile() != "")
                {
                    DialogResult savePrompt = MessageBox.Show("Would you like to save the current working file?", "Lock Current File", MessageBoxButtons.YesNo);
                    if (savePrompt == DialogResult.Yes)
                    {
                        DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1);
                        FileOP.WriteToFile(dataTable);
                    }
                    ClearMem();
                }
                //call the create file method and inflate the next form
                if (FileOP.CreateFile())
                {
                    PasswordOptions passwordOptionsForm;

                    // Creates a passwordOptions form with the correct theme
                    if (darkThemeEnabled)
                    {
                        passwordOptionsForm = new PasswordOptions(Color.White, Color.DarkGray, Color.DarkSlateGray, darkThemeEnabled)
                        {
                            TheParent = this
                        };
                    }
                    else
                    {
                        passwordOptionsForm = new PasswordOptions(SystemColors.ControlText, SystemColors.Window, SystemColors.Control, darkThemeEnabled)
                        {
                            TheParent = this
                        };
                    }

                    // Adding all the password options components to the list of components in the master from.
                    // This is done to apply the same theme and text size to all of the forms
                    textBoxes.AddRange(passwordOptionsForm.passwordOptionsTextBoxes);
                    labels.AddRange(passwordOptionsForm.passwordOptionsLabels);
                    this.buttons.AddRange(passwordOptionsForm.passwordOptionsButtons);
                    forms.Add(passwordOptionsForm);

                    // Changing text size of passwordOptions
                    if (defaultTextSizeEnabled)
                    {
                        ChangeFontSize(8.0f);
                        passwordOptionsForm.passwordOptionsDefaultTextSizeEnabled = true;
                        passwordOptionsForm.passwordOptionsSmallTextSizeEnabled   = false;
                        passwordOptionsForm.passwordOptionsLargeTextSizeEnabled   = false;
                    }

                    else if (smallTextSizeEnabled)
                    {
                        ChangeFontSize(6.0f);
                        passwordOptionsForm.passwordOptionsDefaultTextSizeEnabled = false;
                        passwordOptionsForm.passwordOptionsSmallTextSizeEnabled   = true;
                        passwordOptionsForm.passwordOptionsLargeTextSizeEnabled   = false;
                    }

                    else if (largeTextSizeEnabled)
                    {
                        ChangeFontSize(10.0f);
                        passwordOptionsForm.passwordOptionsDefaultTextSizeEnabled = false;
                        passwordOptionsForm.passwordOptionsSmallTextSizeEnabled   = false;
                        passwordOptionsForm.passwordOptionsLargeTextSizeEnabled   = true;
                    }

                    passwordOptionsForm.ShowDialog();
                    passwordOptionsForm.Activate();
                }
                ;
            }
        }
예제 #25
0
 /// <summary>
 /// Logs the filepath to the console. Use for testing purposes.
 /// </summary>
 public static void PrintFileName()
 {
     Console.WriteLine(FileOP.GetFile());
 }
예제 #26
0
        /// <summary>
        /// Calls the select file method and shows the next form when the open button is clicked from the file dropdown menu.
        /// </summary>
        private void OpenFileDropDown_Click(object sender, EventArgs e)
        {
            // if there is currently a file open
            if (FileOP.GetFile() != "")
            {
                //open a dialog asking if the consumer would like to save
                DialogResult savePrompt = MessageBox.Show("Would you like to save the current working file?", "Lock Current File", MessageBoxButtons.YesNo);
                // save the file contents
                if (savePrompt == DialogResult.Yes)
                {
                    DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1);
                    UnlockFile();
                    FileOP.WriteToFile(dataTable);
                    LockFile();
                }
                // clear any references to file paths in the memory
                ClearMem();
            }
            // if the dialog from fileOP returns true
            if (FileOP.SelectFile())
            {
                // inflate the next form
                EnterPasswordForFile frm = new EnterPasswordForFile {
                    TheParent = this
                };

                // Adding all the enterPasswordForFile components to the list of components in the master from.
                // This is done to apply the same theme and text size to all of the forms
                textBoxes.AddRange(frm.enterPasswordForFileTextBoxes);
                labels.AddRange(frm.enterPasswordForFileLabels);
                this.buttons.AddRange(frm.enterPasswordForFileButtons);
                forms.Add(frm);

                // Changing theme of enterPasswordForFile
                if (darkThemeEnabled)
                {
                    ChangeTheme(System.Drawing.Color.White, System.Drawing.Color.DarkGray, System.Drawing.Color.DarkSlateGray);
                    frm.enterPasswordForFileDarkThemeEnabled = true;
                }
                else
                {
                    ChangeTheme(System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Window, System.Drawing.SystemColors.Control);
                    frm.enterPasswordForFileDarkThemeEnabled = false;
                }

                // Changing text size of enterPasswordForFile
                if (defaultTextSizeEnabled)
                {
                    ChangeFontSize(8.0f);
                    frm.enterPasswordForFileDefaultTextSizeEnabled = true;
                    frm.enterPasswordForFileSmallTextSizeEnabled   = false;
                    frm.enterPasswordForFileLargeTextSizeEnabled   = false;
                }

                else if (smallTextSizeEnabled)
                {
                    ChangeFontSize(6.0f);
                    frm.enterPasswordForFileDefaultTextSizeEnabled = false;
                    frm.enterPasswordForFileSmallTextSizeEnabled   = true;
                    frm.enterPasswordForFileLargeTextSizeEnabled   = false;
                }

                else if (largeTextSizeEnabled)
                {
                    ChangeFontSize(10.0f);
                    frm.enterPasswordForFileDefaultTextSizeEnabled = false;
                    frm.enterPasswordForFileSmallTextSizeEnabled   = false;
                    frm.enterPasswordForFileLargeTextSizeEnabled   = true;
                }

                frm.ShowDialog();
            }
        }