0% found this document useful (0 votes)
6 views

Mini Project.java

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Mini Project.java

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Project Assignment

CSN203
Introduction to Java Programming

Submitted By
Rollno:230102563
SAPID:1000021205
Name :Ujjwal Bharti
Section: O

Submitted to

Mr. Ravi Dhaundiyal, Assistant Professor,


School of Computing
Introduction

In an era where online security is paramount, creating strong and unique passwords has
become a fundamental aspect of protecting personal and sensitive information. Passwords
serve as the first line of defense against unauthorized access to accounts, sensitive data, and
personal information. However, many users still rely on weak or easily guessable passwords,
making them vulnerable to cyber threats such as hacking, phishing, and identity theft.

Generating random passwords is an essential aspect of cybersecurity, ensuring the protection


of sensitive information and online accounts. A strong, unique password is the first line of
defense against unauthorized access and cyber threats.

To address this issue, it is essential to employ a systematic approach to generating secure


passwords. A strong password typically consists of a mix of uppercase letters, lowercase
letters, digits, and special characters. This complexity makes it significantly harder for
malicious actors to crack passwords through brute-force attacks or guessing.

The following Java program demonstrates how to create a random password generator using
core programming concepts such as StringBuilder, the Random class, loops, and character
manipulation. This program allows users to specify the length of the password and select
which types of characters to include, ensuring that the generated password meets their
security requirements. By leveraging these programming techniques, users can easily create
strong passwords that enhance their online security.

Code
package project;
import java.util.Random;
import java.util.Scanner;
public class password {
private static final String LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
private static final String UPPERCASE =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final String NUMBERS = "0123456789";
private static final String SPECIAL_CHARS = "!@#$%^&*()_+";

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
System.out.print("Enter password length: ");
int length = scanner.nextInt();
System.out.print("Include lowercase letters? (y/n): ");
boolean includeLowercase = scanner.next().equalsIgnoreCase("y");
System.out.print("Include uppercase letters? (y/n): ");
boolean includeUppercase = scanner.next().equalsIgnoreCase("y");
System.out.print("Include numbers? (y/n): ");
boolean includeNumbers = scanner.next().equalsIgnoreCase("y");
System.out.print("Include special characters? (y/n): ");
boolean includeSpecialChars = scanner.next().equalsIgnoreCase("y");
String password = generatePassword(length, includeLowercase,
includeUppercase, includeNumbers, includeSpecialChars);
System.out.println("Generated Password: " + password);
}

private static String generatePassword(int length, boolean includeLowercase,


boolean includeUppercase, boolean includeNumbers, boolean includeSpecialChars) {
StringBuilder password = new StringBuilder(length);
Random random = new Random();
String charSet = "";
if (includeLowercase) charSet += LOWERCASE;
if (includeUppercase) charSet += UPPERCASE;
if (includeNumbers) charSet += NUMBERS;
if (includeSpecialChars) charSet += SPECIAL_CHARS;
for (int i = 0; i < length; i++) {
int randomIndex = random.nextInt(charSet.length());
password.append(charSet.charAt(randomIndex));
}

return password.toString();
}
}
Output
Conclusion
In conclusion, generating random passwords is a critical step in enhancing cybersecurity and
protecting personal information. By utilizing Java's StringBuilder, Random class, and
loops, we can create a flexible and efficient password generator that meets specific
requirements for password complexity and length.

This program provides a solid foundation for creating secure passwords. You can easily
modify the character sets or the length of the passwords to suit your needs. Additionally,
consider implementing further enhancements, such as ensuring that the generated password
contains at least one character from each character set, which can further increase the strength
of the password.

In a world where cyber threats are rampant, adopting best practices for password
management is essential. By generating strong, unique passwords, you significantly reduce
the risk of unauthorized access to your accounts and sensitive data. Always remember to
update your passwords regularly and utilize password managers to keep track of them
securely.

You might also like