代码如下: public static class RandomPassword { // Define default min and max password lengths. private static int DEFAULT_MIN_PASSWORD_LENGTH = 8; private static int DEFAULT_MAX_PASSWORD_LENGTH = 10;
/// <summary> /// Generates a random password. /// </summary> /// <returns> /// Randomly generated password. /// </returns> /// <remarks> /// The length of the generated password will be determined at /// random. It will be no shorter than the minimum default and /// no longer than maximum default. /// </remarks> public static string Generate() { return Generate(DEFAULT_MIN_PASSWORD_LENGTH, DEFAULT_MAX_PASSWORD_LENGTH); }
/// <summary> /// Generates a random password of the exact length. /// </summary> /// <param name="length"> /// Exact password length. /// </param> /// <returns> /// Randomly generated password. /// </returns> public static string Generate(int length) { return Generate(length, length); }