Esempio n. 1
0
        private bool NewDocument(bool confirmPassword)
        {
            _passwordSet = false;

            while (!_passwordSet)
            {
                try
                {
                    using (var passwordEntry = new PasswordEntry())
                    {
                        passwordEntry.LabelText = "Stage 1 : Please enter your document passwords.";

                        if (passwordEntry.ShowDialog() != DialogResult.OK)
                        {
                            return(false);
                        }

                        if (confirmPassword)
                        {
                            if (ConfirmationPassword(passwordEntry) == false)
                            {
                                return(false);
                            }
                        }

                        _currentDocument = new Document(passwordEntry.Password);
                        _documentChanged = false;
                        _passwordSet     = true;

                        if (passwordEntry.IsPasswordCached)
                        {
                            _cachedPassword = passwordEntry.Password;
                        }
                    }
                }
                catch (ArgumentNullException)
                {
                    Debug.WriteLine("Argument Null Exception Caught.");
                }
            }

            toolStripStatusLabel.Text = @"New Document Created...";
            return(true);
        }
Esempio n. 2
0
        private static bool ConfirmationPassword(PasswordEntry passwordEntry)
        {
            using (var passwordEntry2 = new PasswordEntry(false))
            {
                passwordEntry2.LabelText = "Stage 2 : Please confirm your document passwords.";

                if (passwordEntry2.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }

                bool password1Match = ByteHelpers.ByteArrayCompare(passwordEntry.Password.Password1, passwordEntry2.Password.Password1);
                bool password2Match = ByteHelpers.ByteArrayCompare(passwordEntry.Password.Password2, passwordEntry2.Password.Password2);

                if ((password1Match == false) || (password2Match == false))
                {
                    MessageBox.Show(Resources.MainForm_ConfirmationPassword_The_passwords_do_not_match_, Resources.MainForm_ConfirmationPassword_Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    return(false);
                }

                return(true);
            }
        }