/// <summary>
        /// Gets the random character.
        /// </summary>
        /// <param name="type">One of the <see cref="PowerShellReturnType"/> enumeration value.</param>
        /// <returns>A random character that corresponds to the specified <see cref="PowerShellReturnType"/> enumeration value.</returns>
        private static char GetRandomCharacter(PasswordCharType type)
        {
            Logger.Instance.WriteMethodEntry(EventIdentifier.PasswordGeneratorGetRandomCharacter, "PasswordCharType: '{0}'.", type);

            try
            {
                // Determine if a standard, special, or numeric character
                // will be returned based on the supplied Boolean value
                int randomIndex;
                switch (type)
                {
                case PasswordCharType.Special:

                    // Generate a random number which represents an
                    // index of the password special character array
                    randomIndex = GetNextRandomNumber(0, PwdSpecialChars.Length - 1);
                    return(PwdSpecialChars[randomIndex]);

                case PasswordCharType.Number:

                    // Generate a random number which represents an
                    // index of the password number array
                    randomIndex = GetNextRandomNumber(0, PwdNumbers.Length - 1);
                    return(PwdNumbers[randomIndex]);

                default:

                    // Generate a random number which represents an
                    // index of the password character array
                    randomIndex = GetNextRandomNumber(0, PwdChars.Length - 1);
                    return(PwdChars[randomIndex]);
                }
            }
            finally
            {
                Logger.Instance.WriteMethodExit(EventIdentifier.PasswordGeneratorGetRandomCharacter, "PasswordCharType: '{0}'.", type);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the random character.
        /// </summary>
        /// <param name="type">One of the <see cref="PowerShellReturnType"/> enumeration value.</param>
        /// <returns>A random character that corresponds to the specified <see cref="PowerShellReturnType"/> enumeration value.</returns>
        private static char GetRandomCharacter(PasswordCharType type)
        {
            Logger.Instance.WriteMethodEntry(EventIdentifier.PasswordGeneratorGetRandomCharacter, "PasswordCharType: '{0}'.", type);

            try
            {
                // Determine if a standard, special, or numeric character
                // will be returned based on the supplied Boolean value
                int randomIndex;
                switch (type)
                {
                    case PasswordCharType.Special:

                        // Generate a random number which represents an
                        // index of the password special character array
                        randomIndex = GetNextRandomNumber(0, PwdSpecialChars.Length - 1);
                        return PwdSpecialChars[randomIndex];

                    case PasswordCharType.Number:

                        // Generate a random number which represents an
                        // index of the password number array
                        randomIndex = GetNextRandomNumber(0, PwdNumbers.Length - 1);
                        return PwdNumbers[randomIndex];

                    default:

                        // Generate a random number which represents an
                        // index of the password character array
                        randomIndex = GetNextRandomNumber(0, PwdChars.Length - 1);
                        return PwdChars[randomIndex];
                }
            }
            finally
            {
                Logger.Instance.WriteMethodExit(EventIdentifier.PasswordGeneratorGetRandomCharacter, "PasswordCharType: '{0}'.", type);
            }
        }