├── PasswordGenerator.java └── README.md /PasswordGenerator.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | 3 | public class Tester{ 4 | public static void main(String[] args) { 5 | System.out.println(generatePassword(8)); 6 | } 7 | 8 | private static char[] generatePassword(int length) { 9 | String capitalCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 10 | String lowerCaseLetters = "abcdefghijklmnopqrstuvwxyz"; 11 | String specialCharacters = "!@#$"; 12 | String numbers = "1234567890"; 13 | String combinedChars = capitalCaseLetters + lowerCaseLetters + specialCharacters + numbers; 14 | Random random = new Random(); 15 | char[] password = new char[length]; 16 | 17 | password[0] = lowerCaseLetters.charAt(random.nextInt(lowerCaseLetters.length())); 18 | password[1] = capitalCaseLetters.charAt(random.nextInt(capitalCaseLetters.length())); 19 | password[2] = specialCharacters.charAt(random.nextInt(specialCharacters.length())); 20 | password[3] = numbers.charAt(random.nextInt(numbers.length())); 21 | 22 | for(int i = 4; i< length ; i++) { 23 | password[i] = combinedChars.charAt(random.nextInt(combinedChars.length())); 24 | } 25 | return password; 26 | } 27 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Password Generator in Java 🎉 2 | 3 | This Java program generates random passwords based on user-defined criteria. 4 | 5 | ## Introduction ℹ️ 6 | 7 | The Password Generator program allows users to create strong and secure passwords for various purposes, such as online accounts, applications, and more. 8 | 9 | ## Features ✨ 10 | 11 | - **Customizable Parameters**: Allows users to specify the length and complexity of the generated password. 12 | - **Randomized Characters**: Generates passwords with random combinations of alphanumeric characters, symbols, and special characters. 13 | - **Secure Passwords**: Ensures the creation of strong and secure passwords to enhance online security. 14 | - **Simple Interface**: Easy-to-use command-line interface for generating passwords. 15 | 16 | ## Usage 🖥️ 17 | 18 | 1. Clone or download the repository. 19 | 2. Compile the `PasswordGenerator.java` file. 20 | 3. Run the compiled Java program. 21 | 4. Follow the instructions to specify the length and complexity of the password. 22 | 5. The program will generate and display a strong and secure password. 23 | 24 | ## Example 25 | 26 | ```bash 27 | $ javac PasswordGenerator.java 28 | $ java PasswordGenerator 29 | Enter the length of the password: 12 30 | Include uppercase letters? (yes/no): yes 31 | Include lowercase letters? (yes/no): yes 32 | Include numbers? (yes/no): yes 33 | Include symbols? (yes/no): yes 34 | Generated password: aF7*2bK#9PqD 35 | 36 | --------------------------------------------------------------------------------