private static PasswordGeneratorProfile ReadPasswordProfile(XmlReader reader)
        {
            var tmpPasswordProfile = new PasswordGeneratorProfile();

            if (SkipEmptyElement(reader))
            {
                return(tmpPasswordProfile);
            }

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            reader.ReadStartElement();
            reader.MoveToContent();

            while (true)
            {
                var tmpNodeType = reader.NodeType;
                if (tmpNodeType == XmlNodeType.None || tmpNodeType == XmlNodeType.EndElement)
                {
                    break;
                }

                if (tmpNodeType == XmlNodeType.Element)
                {
                    switch (reader.LocalName)
                    {
                    default:
                        reader.Skip();
                        break;

                    case "UsingAllNumeric":
                        tmpPasswordProfile.UsingAllNumeric = ReadBoolean(reader);
                        break;

                    case "Length":
                        tmpPasswordProfile.Length = ReadUInt32(reader);
                        break;

                    case "UsingUpperCase":
                        tmpPasswordProfile.UsingUpperCase = ReadBoolean(reader);
                        break;

                    case "UsingLowerCase":
                        tmpPasswordProfile.UsingLowerCase = ReadBoolean(reader);
                        break;

                    case "UsingDigitChars":
                        tmpPasswordProfile.UsingDigitChars = ReadBoolean(reader);
                        break;

                    case "UsingMinusChar":
                        tmpPasswordProfile.UsingMinusChar = ReadBoolean(reader);
                        break;

                    case "UsingUnderline":
                        tmpPasswordProfile.UsingUnderline = ReadBoolean(reader);
                        break;

                    case "UsingSpaceChar":
                        tmpPasswordProfile.UsingSpaceChar = ReadBoolean(reader);
                        break;

                    case "UsingSpecialChars":
                        tmpPasswordProfile.UsingSpecialChars = ReadBoolean(reader);
                        break;

                    case "UsingBracketChars":
                        tmpPasswordProfile.UsingBracketChars = ReadBoolean(reader);
                        break;

                    case "ExcludeLookAlike":
                        tmpPasswordProfile.ExcludeLookAlike = ReadBoolean(reader);
                        break;

                    case "NoRepeatingChars":
                        tmpPasswordProfile.NoRepeatingChars = ReadBoolean(reader);
                        break;

                    case "ExcludeCharacters":
                        tmpPasswordProfile.ExcludeCharacters = ReadString(reader);
                        break;
                    }

                    reader.MoveToContent();
                }
            }

            reader.ReadEndElement();

            return(tmpPasswordProfile);
        }
Exemplo n.º 2
0
        protected override void OnLoad(System.EventArgs args)
        {
            base.OnLoad(args);

            if (!base.DesignMode)
            {
                this.blockUpdateControls = true;

                this.CancelButton = this.buttonCancel;
                this.numericPasswordLength.Minimum = 1;
                this.numericPasswordLength.Maximum = 100;
                this.numericPasswordLength.Value   = 16;
                this.textExcludeChars.ImeMode      = ImeMode.Disable;

                this.textBoxPassword.ReadOnly           = true;
                this.textBoxPassword.Multiline          = true;
                this.textBoxPassword.SelectionAlignment = HorizontalAlignment.Center;

                this.Icon              = WindowsUtils.DefaultAppIcon;
                this.Text              = SafePassResource.PasswordGeneratorWindowCaption;
                this.buttonOK.Text     = SafePassResource.ButtonOK;
                this.buttonCancel.Text = SafePassResource.ButtonCancel;

                this.buttonGenerate.Text        = SafePassResource.PasswordGeneratorButtonGenerate;
                this.groupPasswordOptions.Text  = SafePassResource.PasswordGeneratorPasswordOptions;
                this.groupAdvancedOptions.Text  = SafePassResource.PasswordGeneratorAdvancedOptions;
                this.groupGeneratePassword.Text = SafePassResource.PasswordGeneratorGroupPassword;
                this.radioUsingNumeral.Text     = SafePassResource.PasswordGeneratorRadioUsingNumeral;
                this.radioUsingCharacter.Text   = SafePassResource.PasswordGeneratorRadioUsingCharacter;
                this.labelPasswordLength.Text   = SafePassResource.PasswordGeneratorLabelPasswordLength;

                this.checkUpperCase.Text        = SafePassResource.PasswordGeneratorCheckBoxUpperCase;
                this.checkLowerCase.Text        = SafePassResource.PasswordGeneratorCheckBoxLowerCase;
                this.checkDigitChars.Text       = SafePassResource.PasswordGeneratorCheckBoxDigitChars;
                this.checkMinusChar.Text        = SafePassResource.PasswordGeneratorCheckBoxMinusChar;
                this.checkUnderline.Text        = SafePassResource.PasswordGeneratorCheckBoxUnderline;
                this.checkSpaceChar.Text        = SafePassResource.PasswordGeneratorCheckBoxSpaceChar;
                this.checkSpecialChars.Text     = SafePassResource.PasswordGeneratorCheckBoxSpecialChars;
                this.checkBracketChars.Text     = SafePassResource.PasswordGeneratorCheckBoxBracketChars;
                this.checkExcludeChars.Text     = SafePassResource.PasswordGeneratorCheckBoxExcludeChars;
                this.checkNoRepeatingChars.Text = SafePassResource.PasswordGeneratorCheckBoxNoRepeatingChars;
                this.checkExcludeLookAlike.Text = SafePassResource.PasswordGeneratorCheckBoxExcludeLookAlike;

                this.checkUpperCase.Text        += " (A, B, C, B, B, ...)";
                this.checkLowerCase.Text        += " (a, b, c, b, b, ...)";
                this.checkDigitChars.Text       += " (0, 1, 2, 3, 4, 5, ...)";
                this.checkMinusChar.Text        += " (-)";
                this.checkUnderline.Text        += " (_)";
                this.checkSpaceChar.Text        += " ( )";
                this.checkBracketChars.Text     += " ([, ], {, }, (, ), <, >)";
                this.checkSpecialChars.Text     += " (!, $, %, &&, #, *, +, :, ;, =, ?, @, \", ', ^, `, ~, ,, ., |, \\, /)";
                this.checkExcludeLookAlike.Text += " (O0, l|1I)";

                this.originalProfile = Program.Config.Application.PasswordGenerator;

                this.radioUsingNumeral.Checked   = this.originalProfile.UsingAllNumeric;
                this.radioUsingCharacter.Checked = !this.radioUsingNumeral.Checked;
                this.checkUpperCase.Checked      = this.originalProfile.UsingUpperCase;
                this.checkLowerCase.Checked      = this.originalProfile.UsingLowerCase;
                this.checkDigitChars.Checked     = this.originalProfile.UsingDigitChars;
                this.checkMinusChar.Checked      = this.originalProfile.UsingMinusChar;
                this.checkUnderline.Checked      = this.originalProfile.UsingUnderline;
                this.checkSpaceChar.Checked      = this.originalProfile.UsingSpaceChar;
                this.checkSpecialChars.Checked   = this.originalProfile.UsingSpecialChars;
                this.checkBracketChars.Checked   = this.originalProfile.UsingBracketChars;

                if (this.originalProfile.Length >= this.numericPasswordLength.Minimum && this.originalProfile.Length <= this.numericPasswordLength.Maximum)
                {
                    this.numericPasswordLength.Value = this.originalProfile.Length;
                }

                this.checkNoRepeatingChars.Checked = this.originalProfile.NoRepeatingChars;
                this.checkExcludeLookAlike.Checked = this.originalProfile.ExcludeLookAlike;
                if (string.IsNullOrEmpty(this.originalProfile.ExcludeCharacters))
                {
                    this.checkExcludeChars.Checked = false;
                }
                else
                {
                    this.checkExcludeChars.Checked = true;
                    this.textExcludeChars.Text     = this.originalProfile.ExcludeCharacters;
                }

                this.blockUpdateControls = false;
                this.UpdateControlState();
            }
        }