mercredi 13 septembre 2017

Does creating a password using random will definitely create a password with letters(capital+small),special characters,numbers? [duplicate]

This question already has an answer here:

I tried using the below code to generate the password but usage of capital letter,small letter,special character and number were not mandatory when I was testing it.It was skipping either of those sometimes.How to consider those as mandatory for every password for a length of 8 .I also want to know how many random unique password it will generate

   public static void main(String[] args)
        {
            // Length of your password as I have choose
            // here to be 8
            int length = 8;
            System.out.println(geek_Password(length));
        }

        // This our Password generating method
        // We have use static here, so that we not to
        // make any object for it
        static char[] geek_Password(int len)
        {
            System.out.println("Generating password using random() : ");
            System.out.print("Your new password is : ");

            // A strong password has Cap_chars, Lower_chars,
            // numeric value and symbols. So we are using all of
            // them to generate our password
            String Capital_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            String Small_chars = "abcdefghijklmnopqrstuvwxyz";
            String numbers = "0123456789";
                    String symbols = "!@#$%^&*_=+-/.?<>)";


            String values = Capital_chars + Small_chars +
                            numbers + symbols;

            // Using random method
            Random rndm_method = new Random();

            char[] password = new char[len];

            for (int i = 0; i < len; i++)
            {
                // Use of charAt() method : to get character value
                // Use of nextInt() as it is scanning the value as int
                password[i] =
                  values.charAt(rndm_method.nextInt(values.length()));

            }
            return password;
        }




Aucun commentaire:

Enregistrer un commentaire