Beispiel #1
0
        void LoadFile(string path, bool OpenWithValidation)
        {
            PasswordsGrd.Rows.Clear();
            try
            {
                file = PasswordsFile.Load(path);
                bool passwordIsOk           = false;
                MasterPasswordInput_frm frm = new MasterPasswordInput_frm(file.MasterPassword);

                if (OpenWithValidation)
                {
                    passwordIsOk = frm.ShowDialog() == DialogResult.OK;
                }


                if ((OpenWithValidation && passwordIsOk) || OpenWithValidation == false)
                {
                    DisplayPasswords(file.Passwords);
                }
                else
                {
                    Close();
                }
            }
            catch
            {
                var result = MessageBox.Show("Faild To Open Passwords File.Do You Want To ReCreate It?", "Open Failed", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    CreateFileFrm frm2 = new CreateFileFrm(path);
                    frm2.ShowDialog();
                }
            }
        }
 void Save()
 {
     if (!string.IsNullOrEmpty(NewPassTxt.Text))
     {
         PasswordsFile file = PasswordsFile.Load(path);
         if (PasswordTxt.Text == file.MasterPassword)
         {
             if (NewPassTxt.Text == ConfirmTxt.Text)
             {
                 file.MasterPassword = NewPassTxt.Text;
                 file.Save(path);
                 Close();
             }
             else
             {
                 MessageBox.Show("Password Confirm Doesn't Match.");
             }
         }
         else
         {
             MessageBox.Show("Old Password Is Incorrect.");
         }
     }
     else
     {
         MessageBox.Show("Enter the New Password.");
     }
 }
        /// <summary>
        /// Save Current Passwords And Master Password File in Specific Path.
        /// </summary>
        /// <param name="path">File Location To Save.</param>
        public void Save(string path)
        {
            PasswordsFile   file = new PasswordsFile();
            FileStream      fs   = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
            BinaryFormatter Bf   = new BinaryFormatter();

            Bf.Serialize(fs, this);
            fs.Close();
        }
Beispiel #4
0
        private void ExportBtn_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Passwords File|*.mps";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if (PasswordsGrd.SelectedRows.Count > 0)
                {
                    //Create New File To Export To
                    PasswordsFile newfile = new PasswordsFile();
                    newfile.Passwords = new List <Password>();
                    foreach (DataGridViewRow row in PasswordsGrd.SelectedRows)
                    {
                        Password password = new Password()
                        {
                            password = row.Cells["Password_col"].Value.ToString(),
                            UserName = row.Cells["UserName_col"].Value.ToString(),
                            LNK      = row.Cells["Link_col"].Value.ToString(),
                            Details  = row.Cells["details_col"].Value.ToString(),
                        };
                        newfile.Passwords.Add(password);
                    }
                    //Save With The Same MasterPassword Or Create New
                    var result = MessageBox.Show("Do You Want To Set Master Password?", "new MasterPassword", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        CreateFileFrm frm = new CreateFileFrm(sfd.FileName);
                        if (frm.ShowDialog() == DialogResult.OK)
                        {
                            newfile.MasterPassword = frm.Password;
                        }
                        else
                        {
                            MessageBox.Show("You Have Canceld new Password Creation.File Will Be saved With Current Master Password.");
                            newfile.MasterPassword = file.MasterPassword;
                        }
                    }
                    else
                    {
                        newfile.MasterPassword = file.MasterPassword;
                    }
                    newfile.Save(sfd.FileName);
                }
                else
                {
                    file.Save(sfd.FileName);
                }

                MessageBox.Show("passwords Was Successfully Exported");
            }
        }
Beispiel #5
0
        public Password_AE(int id, string path)
        {
            InitializeComponent();
            this.id   = id;
            this.path = path;
            //Retrive Password Details
            PasswordsFile passwordfile = PasswordsFile.Load(path);
            var           password     = passwordfile.Passwords.FirstOrDefault(x => x.ID == id);

            Passwordtxt.Text = password.password;
            UserNameTxt.Text = password.UserName;
            Linktxt.Text     = password.LNK;
            DetailsTxt.Text  = password.Details;
        }
        /// <summary>
        /// Load File From Specific Path
        /// </summary>
        /// <param name="path">Location Of File</param>
        /// <returns>Passwords File</returns>
        public static PasswordsFile Load(string path)
        {
            PasswordsFile   file = new PasswordsFile();
            FileStream      fs   = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None);
            BinaryFormatter Bf   = new BinaryFormatter();

            if (File.Exists(path))
            {
                file = (PasswordsFile)Bf.Deserialize(fs);
            }
            else
            {
                throw new FileNotFoundException();
            }
            fs.Close();
            return(file);
        }
Beispiel #7
0
        void Save()
        {
            PasswordsFile passwordfile = PasswordsFile.Load(path);

            if (!string.IsNullOrEmpty(Passwordtxt.Text))
            {
                Password password = new Password();
                if (id != 0)
                {
                    password = passwordfile.Passwords.FirstOrDefault(x => x.ID == id);
                }
                else
                {
                    int maxid = 0;
                    if (passwordfile.Passwords == null)
                    {
                        passwordfile.Passwords = new List <Password>();
                    }
                    else if (passwordfile.Passwords.Count > 0)
                    {
                        maxid = passwordfile.Passwords.Max(x => x.ID);
                    }
                    password.ID = maxid + 1;

                    passwordfile.Passwords.Add(password);
                }
                password.password = Passwordtxt.Text;
                password.UserName = UserNameTxt.Text;
                password.LNK      = Linktxt.Text;
                password.Details  = DetailsTxt.Text;

                passwordfile.Save(path);
                Close();
            }
            else
            {
                MessageBox.Show("Please Enter Password.");
            }
        }
Beispiel #8
0
 void Save()
 {
     if (string.IsNullOrEmpty(PasswordTxt.Text))
     {
         MessageBox.Show("Please Enter Password.");
     }
     else
     {
         if (PasswordTxt.Text == ConfirmTxt.Text)
         {
             PasswordsFile file = new PasswordsFile();
             file.MasterPassword = PasswordTxt.Text;
             file.Save(path);
             this.DialogResult = DialogResult.OK;
             Password          = PasswordTxt.Text;
             Close();
         }
         else
         {
             MessageBox.Show("Password And Confirm Doesn't Match");
         }
     }
 }