C#密码生成器

时间:2016-06-15 11:40:00

标签: c#

大家好我想知道用最少一个数字和一个特殊字符生成密码的最佳方法是什么,并且至少有一个大写字母。

 private static string PassGEN()
    {
        int i;
        int seed = rand.Next(1,2);
        var  CaptialChars = "QWERTYUIOPASDFGHJKLZXCVBNM";
        var  smallChars = "qwertyuiopasdfghjklzxcvbnm";
        var  numbers = "9462537810";
        var  specialCharacters = @"!$%*-/=?\_";

        var sma = CaptialChars[rand.Next(1, CaptialChars.Length)];
        var sm = smallChars[rand.Next(1, smallChars.Length)];
        var smb = numbers[rand.Next(1, numbers.Length)];
        var smc = specialCharacters[rand.Next(1, specialCharacters.Length)];

        //int seeded = sma + sm + smb + smc;



        var all = CaptialChars + smallChars + numbers + specialCharacters;

        /*
        int CapLenght = 2;
        int smallLenght = 2;
        int num = 2;
        int special = 2;
        int  passwordLength = CapLenght + smallLenght + num + special;
        */

        int passwordLength = 8;
        var chars = new char[passwordLength];
        var rd = new Random(seed);

        for (i = 0; i < passwordLength; i++) 
        {
            chars[i] = all[rd.Next(0, all.Length)];
        }
         return new string(chars);
    }

0 个答案:

没有答案