Exemplo n.º 1
0
        static String generatePassword(PasswordStrength password)
        {
            StringBuilder newPassword = new StringBuilder();
            Random        random      = new Random();
            String        allChars    = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`!@#$%^&*()_-+=";

            //0-26 small
            //27-53 caps
            //54-63 numbers
            //63-79 special chars
            if (password.Equals(PasswordStrength.easy)) // generate Easy, 6 mali bukvi
            {
                int length = random.Next(1, 6);         // LENGTH OF PASSWORD
                for (int i = 0; i < length; i++)
                {
                    int num = random.Next(0, 26);
                    newPassword.Append(allChars.ElementAt(num));
                }
            }
            else if (password.Equals(PasswordStrength.normal)) // generate Normal, 6-10 golemi bukvi i broevi
            {
                int length = random.Next(6, 10);               // LENGTH OF PASSWORD
                for (int i = 0; i < length; i++)
                {
                    int num = random.Next(27, 63);
                    newPassword.Append(allChars.ElementAt(num));
                }
            }
            else if (password.Equals(PasswordStrength.hard)) // generate Hard, 10+ bukvi, broevi, specijalni znaci
            {
                int length = random.Next(10, 20);            // LENGTH OF PASSWORD MY MAX=20 chars
                for (int i = 0; i < length; i++)
                {
                    int num = random.Next(0, 79);
                    newPassword.Append(allChars.ElementAt(num));
                }
            }
            return(newPassword.ToString());
        }