欢迎来到Chaosmos!

我们提供免费辅助,破解辅助,成人资源,包括黑客技术交流等版块;相信您一定能在这里找到您想要的。

立即注册!
  • 为了确保论坛积极互助的氛围,本论坛需要下载的资源一律必须在回复帖子之后才能进行下载。对于非附件内容也鼓励开启隐藏回复/反应可见模式!

    VIP用户可以免回复帖子下载资源,升级为VIP可通过发表超过15条贴子或消息后自动升级为VIP用户。

  • Chaosmos官方电报频道:https://t.me/metastemsu Chaosmos官方电报群聊: https://t.me/chinahvh

开源 密码生成器源码 | C#

Sky

候补委员
gemgemgemgemgem
管理成员
政治局委员
优秀干部
注册
2024/07/29
消息
122
C#:
using System;
using System.Security.Cryptography;

class PasswordGenerator
{
    private const string UppercaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private const string LowercaseChars = "abcdefghijklmnopqrstuvwxyz";
    private const string DigitChars = "0123456789";
    private const string SpecialChars = "!@#$%^&*()-_=+[]{}|;:'\",.<>/?";

    private static Random random = new Random();

    public static string GeneratePassword(int length, bool includeUppercase, bool includeLowercase, bool includeDigits, bool includeSpecialChars)
    {
        string validChars = "";

        if (includeUppercase)
            validChars += UppercaseChars;
        if (includeLowercase)
            validChars += LowercaseChars;
        if (includeDigits)
            validChars += DigitChars;
        if (includeSpecialChars)
            validChars += SpecialChars;

        if (validChars.Length == 0)
            throw new ArgumentException("At least one character set must be selected.");

        char[] password = new char[length];
        using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
        {
            int max = validChars.Length;

            for (int i = 0; i < length; i++)
            {
                byte[] randomNumber = new byte[1];
                rng.GetBytes(randomNumber);
                int index = Convert.ToInt32(randomNumber[0]) % max;
                password[i] = validChars[index];
            }
        }

        return new string(password);
    }

    static void Main()
    {
        int passwordLength = 12;
        bool includeUppercase = true;
        bool includeLowercase = true;
        bool includeDigits = true;
        bool includeSpecialChars = true;

        string password = GeneratePassword(passwordLength, includeUppercase, includeLowercase, includeDigits, includeSpecialChars);
        Console.WriteLine("Generated Password: " + password);
    }
}
 

magicdog20

同志
gemgemgem
普通党员
优秀干部
注册
2024/08/22
消息
25
well
 
顶部