PASSWORD GENERATOR:
The purpose of a Password Generator project is to create strong, random, and secure passwords to help
users protect their online accounts. The project's scope is to provide a tool that can generate passwords
based on user-specified criteria, such as length and the inclusion of different character types (uppercase
letters, lowercase letters, numbers, and special symbols).
My Development process:
1. Process Planning and Design:
I began by outlining the necessary features and
functionalities for the password generator. This included
defining the core requirements, such as the ability for a
user to specify the length and character sets for their
password.
2. Tooling and Development Environment:
I initially attempted to use the Eclipse IDE, but I faced
some challenges because it was my first time using it, and
the installation process was time-consuming. I smartly
decided to switch to OnlineGDB, an online compiler,
which allowed me to proceed with coding more
efficiently.
3. Core Algorithm Development:
To create the random password generation logic, I used
the random package to import random functions. I also
implemented various character sets (e.g., lowercase
letters, uppercase letters, numbers, symbols) using
strings, which is a fundamental part of a password
generator.
4. User Input Handling:
I created two methods to handle user input: one for the
desired length of the password and another for the
specific character sets the user wants to include. This
step ensures that the generator is customizable based on
user preferences.
5. Integration and Testing:
Finally, I tested my code to ensure it produced the correct
output based on user input. I encountered a few errors
during this process, but I successfully debugged it. The
final result is a working password generator that fulfills
the user's preferences.
Overall, I successfully completed the project from
planning to debugging, and I'm proud of my ability to
adapt to challenges, like switching development
environments, to achieve the final outcome.
Structure of code:
This project is a Java-based password generator
application. It uses the [Link] class to generate
secure, customizable passwords. The program's core
functionality is encapsulated within a PasswordGenerator
class, which manages different character sets (e.g.,
lowercase, uppercase, numbers, and symbols) as private
members. The user interacts with a main class that
utilizes a Scanner object to capture their preferences for
password length and character set. The application
provides two dedicated methods to handle user
preferences and a separate method to produce the final
password, ensuring a simple, reusable, and modular
design.
Code:
import [Link];
import [Link].*;
public class passwordGenerator
{
private static final String UPPERCASE =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final String LOWERCASE =
"abcdefghijklmnopqrstuvwxyz";
private static final String NUMBERS = "1234567890";
private static final String SYMBOLS = "!@#$
%^&*()`~_+{}|:<>?/-,;'[]=*'";
public static void main(String[] args)
{
Scanner scanner = new Scanner([Link]);
[Link]("PASSWORD GENERATOR: Create
unbreakable passwords.");
int length = getPasswordLength(scanner);
String characterPool = getCharacterPool(scanner);
if ([Link]())
{
[Link](" Error: No character set
selected. Defaulting to numbers .");
characterPool = NUMBERS;
}
String password = generatePassword(length,
characterPool);
[Link]("------------------------------");
[Link]("Generated Password: " +
password);
[Link]("------------------------------");
[Link]();
}
private static int getPasswordLength(Scanner scanner)
{
[Link]("Enter the desired password
length: ");
int length = 8;
try
{
length = [Link]([Link]());
if (length <= 0)
{
[Link]("Length must be positive.
Using default length of 8.");
length = 8;
}
}
catch (NumberFormatException e)
{
[Link]("Invalid number format. Using
default length of 8.");
}
return length;
}
private static String getCharacterPool(Scanner scanner)
{
StringBuilder pool = new StringBuilder();
[Link]("Include uppercase letters (ABC)?
(y/n): ");
if ([Link]().equalsIgnoreCase("y"))
{
[Link](UPPERCASE);
}
[Link]("Include lowercase letters (abc)?
(y/n): ");
if ([Link]().equalsIgnoreCase("y"))
{
[Link](LOWERCASE);
}
[Link]("Include numbers (123)? (y/n): ");
if ([Link]().equalsIgnoreCase("y"))
{
[Link](NUMBERS);
}
[Link]("Include special symbols (!@#)?
(y/n): ");
if ([Link]().equalsIgnoreCase("y"))
{
[Link](SYMBOLS);
}
return [Link]();
}
private static String generatePassword(int length,
String pool)
{
Random random = new Random();
char[] password = new char[length];
for (int i = 0; i < length; i++)
{
password[i] =
[Link]([Link]([Link]()));
}
return new String(password);
}
}
Challenges of my code:
A key challenge was initially trying to handle all user
input with a single method. This made the code complex,
so I refactored it into two separate methods,one for
password length and one for character set preferences.
This change made the code much clearer and more
robust.
Another challenge was displaying the generated
password in a graphical box. Since this was a command-
line application, it wasn't feasible. I solved this by using
simple (---) to visually highlight the password in the
console.
Overall, the project successfully uses a modular design
with separate concerns and robust input validation. The
final application is an effective tool for generating
custom, secure passwords.