Coders Packet

Password generator using JAVA

By Avinash Battula

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:

  1. The code defines four strings: upper (uppercase letters), lower (lowercase letters), num (numbers), and specialChars (special characters).

  2. It creates a string called a combination by concatenating the four strings together.

  3. It specifies the desired length of the password (len), which is set to 8 characters in this example.

  4. It creates a character array called password with a length of len to store the generated password.

  5. It creates a new instance of the Random class to generate random indices for selecting characters from the combination string.

  6. 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.

  7. 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:

Password Generator

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Avinash Battula (avinash1911)

Download packets of source code on Coders Packet