Password Generator is a tool that is used by a large number of programmers in their day-to-day life and is also used by most of the users who require additional security for their accounts.
The password generator is written in Java. It generates a random password consisting of uppercase letters, lowercase letters, numbers, and special characters.
Here's a breakdown of how the code works:
The code defines four strings: upper
(uppercase letters), lower
(lowercase letters), num
(numbers), and specialChars
(special characters).
It creates a string called a combination
by concatenating the four strings together.
It specifies the desired length of the password (len
), which is set to 8 characters in this example.
It creates a character array called password
with a length of len
to store the generated password.
It creates a new instance of the Random
class to generate random indices for selecting characters from the combination
string.
It uses a loop to generate each character of the password. In each iteration, it randomly selects a character from the combination
string using the nextInt()
method of the Random
class and stores it in the password
array.
Finally, it converts the password
character array to a string using the new String(password)
constructor and prints the generated password.
When you run this code, it will output a randomly generated password of length 8, consisting of a combination of uppercase letters, lowercase letters, numbers, and special characters.
Sample Output:
Submitted by Avinash Battula (avinash1911)
Download packets of source code on Coders Packet
Comments