Password generator in java

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

This is a Java Console Application to generate Random passwords and performing a Strength check

KZarzour/Password-Generator

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This project is a Java Console Application to generate random passwords and perform password strength checks.

I decided to build this project during the Winter Break of my second year after taking the Object-Oriented Effective Java Programming course. I wanted to build something interesting with Java to practice and see what I could do on my own. However, I still wasn’t sure what I wanted to do. Then one night, while explaining to my father the importance of having a strong password for his social media accounts, I got the idea of creating a random password generator. A week later, it was done.

While working on it, I decided to include a password strength checker feature that checks the overall strength of the entered password. I was pretty happy with how it turned out, but I realized that it was not very straightforward to use for someone who does not know how it is supposed to work. So, I decided to create a GUI for the application for the next step, which is available in the Password-Services repository.

  • The user answers with «Yes» or «No» to questions about using uppercase letters, lowercase letters, numbers, or symbols.
  • The user then enters the desired length of the password.
  • A password alphabet is generated based on the user’s answers, which is a string containing the chosen characters.
  • Random characters from the password alphabet are selected and combined to form a completely random string according to the user’s preferences.
  • The randomly generated password is then displayed on the console.

2. Checking a Password’s Strength:

The strength check is based on the following criteria:

  • The password uses uppercase letters.
  • The password uses lowercase letters.
  • The password uses numbers.
  • The password uses symbols.
  • The length of the password is 8 or more (8 is often the minimum required length for a decent password).
  • The length of the password is 16 or more (16 is considered to be the minimum length for a good password).

These criteria are used to calculate a score for the password, which determines the message displayed to the user indicating the strength of the password (weak/medium/good/great).

3. Displaying Useful Information:

This is a minor feature that displays information for the user on the console about password security, such as avoiding using the same password twice, avoiding character repetition, keyboard patterns, dictionary words, letter or number sequences, etc.

About

This is a Java Console Application to generate Random passwords and performing a Strength check

Источник

Password Generator in Java

In this tutorial, you will learn how to create a password generator in Java. We will create a simple password generator and a strong password generator with a strength checker.

About Password & Password Generator

A password is a secret set of characters that is used for user authentication to get access to a computer system or an application.

A strong password is a combination of alphabets, numbers, and special characters. And it should be at least 8 characters long. The longer the password, the stronger it is.

Hackers can easily crack a weak password using brute force attacks. So, it is important to create a strong password.

The password generator program we are going to see in this tutorial will generate a strong password every time you run it.

Password generator in Java

Simple Password Generator

Let’s first create a simple password generator program in Java. This will give you a basic idea and initial start of how to create a password generator in Java.

To generate a password we will need to choose random characters from a set of characters. For this, we will use the Random class.

Random class is present in java.util package. So, we need to import this package into our program. It provides methods to generate random numbers, boolean, float, double, long, and strings.

Steps to create a simple password generator in Java:

  1. Import java.util.Random package.
  2. Create a function to generate the password. This function will take the size of the password as an argument.
  3. Inside the function, create a string which is a collection of characters that can be added to the password.
  4. Now run a loop that randomly creates a number between 0 and the length of the string. And use this as an index to get a random character from the string. Add this character to the password.
  5. Finally, return the password.
import java.util.Random; import java.util.Scanner; public class generator < // function to generate password static String generate_password(int size) < // collection of characters that can be used in password String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+-/.,<>?;':\"[]<>\\|`~"; String password = ""; // creating object of Random class Random rnd = new Random(); // looping to generate password while (password.length() < size) < // get a random number between 0 and length of chars int index = (int) (rnd.nextFloat() * chars.length()); // add character at index to password password += chars.charAt(index); >return password; > public static void main(String[] args) < Scanner sc = new Scanner(System.in); System.out.print("Enter the size of password: "); int size = sc.nextInt(); sc.close(); // calling function to generate password String password = generate_password(size); // printing the password System.out.println(password); >>
Enter the size of password: 8 I"~|trj% Enter the size of password: 12 Og%AKGy%KS)z

Copy the above code and paste it into a file named generator.java . Then compile and run it.

When you run the program, it will ask you to enter the size of the password. Enter the size and press enter. It will generate a random password of the given size.

Strong Password Generator

There are a few limitations in the simple password generator program we created above. It can generate a password of any size. But you can’t control what type of characters it will use.

For example, if you want to create a password that contains only alphabets, then the simple password generator program will not work. It will generate a password with a mixture of all characters.

So, let’s create a strong password generator program in Java where you can control what type of characters you want to use and also the size of the password.

Steps to create a strong password generator in Java:

  1. Start with importing java.util.Random package.
  2. Now create a Java function that takes 5 parameters. The first parameter is the size of the password. The next 4 parameters are boolean values that indicate whether you want to include uppercase, lowercase, numbers, and special characters in the password.
  3. Define string variables to store upper, lower, number, and special characters.
  4. According to the boolean values, add the characters to the chars variable. Which is the string that will be used to generate the password.
  5. Now create a string variable to store the password, also create a counter variable that counts the types of characters included in the password.
  6. Now include at least one of each type of character in the password. For example, if you want to include uppercase characters, then add one uppercase character to the password.
  7. Create a loop that runs until the length of the password minus the counter variable.
  8. Inside the loop, randomly select a character from the chars variable and add it to the password.
  9. Now shuffle the password for better security.
  10. Finally, return the shuffled password.
import java.util.Random; public class generator < public static void main(String[] args) < System.out.println("Password 1: " + generate_password(8, true, true, true, true)); System.out.println("Password 2: " + generate_password(14, true, false, true, false)); System.out.println("Password 3: " + generate_password(20, false, true, false, true)); >static String generate_password(int size, boolean upper, boolean lower, boolean number, boolean special) < String upper_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String lower_chars = "abcdefghijklmnopqrstuvwxyz"; String number_chars = "1234567890"; String special_chars = "!@#$%^&*()_+-/.,<>?;':\"[]<>\\|`~"; String chars = ""; if (upper) < chars += upper_chars; >if (lower) < chars += lower_chars; >if (number) < chars += number_chars; >if (special) < chars += special_chars; >String password = ""; // include at least one of each type int count = 0; if (upper) < password += upper_chars.charAt((int) (Math.random() * upper_chars.length())); count++; >if (lower) < password += lower_chars.charAt((int) (Math.random() * lower_chars.length())); count++; >if (number) < password += number_chars.charAt((int) (Math.random() * number_chars.length())); count++; >if(special) < password += special_chars.charAt((int) (Math.random() * special_chars.length())); count++; >Random rnd = new Random(); while (password.length() < size-count) < int index = (int) (rnd.nextFloat() * chars.length()); password += chars.charAt(index); >// shuffle the password String shuffled = ""; while (password.length() > 0) < int index = (int) (rnd.nextFloat() * password.length()); shuffled += password.charAt(index); password = password.substring(0, index) + password.substring(index + 1); >return shuffled; > > 
Password 1: 9>Bq Password 2: FCLI5SNLRP4J Password 3: m)bo%|p?rkd\w!a]%"

Strength Checker for Password

Moving with the flow of the tutorial, let’s create a program in Java to check the strength of a password.

There are many ways to check the strength of a password. We will create strength value for a password based on the following criteria:

  • Length of the password.
  • Presence of uppercase characters.
  • Presence of lowercase characters.
  • Presence of numbers.
  • Presence of special characters.

For each criterion, we will assign a value. For example, if the password contains uppercase characters, then we will add 1 to the strength value. If the password contains lowercase characters, then we will add 1 to the strength value. And so on.

import java.util.*; public class z < // function to generate password static String password_strength(String password) < int strength = 0; if (password.length() >= 8) < strength += 1; >if (password.matches(".*[A-Z].*")) < strength += 1; >if (password.matches(".*[a-z].*")) < strength += 1; >if (password.matches(".*9.*")) < strength += 1; >if (password.matches(".*[!@#$%^&*()_+-/.,<>?;':\"<>\\|`~].*")) < strength += 1; >if (strength == 1) < return "Very Weak"; >else if (strength == 2) < return "Weak"; >else if (strength == 3) < return "Medium"; >else if (strength == 4) < return "Strong"; >else if (strength == 5) < return "Very Strong"; >return "Very Weak"; > public static void main(String[] args) < Scanner sc = new Scanner(System.in); System.out.print("Type your password: "); String password = sc.nextLine(); sc.close(); // calling function to check password strength System.out.println("Password Strength: " + password_strength(password)); >>
Type your password: 12345678 Password Strength: Very Weak Type your password: 12345678a Password Strength: Weak Type your password: g32#~hs8&Ad21^7 Password Strength: Very Strong

Conclusion

Summarising the above tutorial, we have learned how to create a password generator in Java. We have also learned how to check the strength of a password in Java.

You can play with the above code to create even stronger passwords. Now i’ts your turn to create a password generator in Java.

Источник

Password generator in java

Learn Latest Tutorials

Splunk tutorial

SPSS tutorial

Swagger tutorial

T-SQL tutorial

Tumblr tutorial

React tutorial

Regex tutorial

Reinforcement learning tutorial

R Programming tutorial

RxJS tutorial

React Native tutorial

Python Design Patterns

Python Pillow tutorial

Python Turtle tutorial

Keras tutorial

Preparation

Aptitude

Logical Reasoning

Verbal Ability

Company Interview Questions

Artificial Intelligence

AWS Tutorial

Selenium tutorial

Cloud Computing

Hadoop tutorial

ReactJS Tutorial

Data Science Tutorial

Angular 7 Tutorial

Blockchain Tutorial

Git Tutorial

Machine Learning Tutorial

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures tutorial

DAA tutorial

Operating System

Computer Network tutorial

Compiler Design tutorial

Computer Organization and Architecture

Discrete Mathematics Tutorial

Ethical Hacking

Computer Graphics Tutorial

Software Engineering

html tutorial

Cyber Security tutorial

Automata Tutorial

C Language tutorial

C++ tutorial

Java tutorial

.Net Framework tutorial

Python tutorial

List of Programs

Control Systems tutorial

Data Mining Tutorial

Data Warehouse Tutorial

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.

  • Website Designing
  • Website Development
  • Java Development
  • PHP Development
  • WordPress
  • Graphic Designing
  • Logo
  • Digital Marketing
  • On Page and Off Page SEO
  • PPC
  • Content Development
  • Corporate Training
  • Classroom and Online Training
  • Data Entry

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week

Like/Subscribe us for latest updates or newsletter RSS Feed Subscribe to Get Email Alerts Facebook Page Twitter Page YouTube Blog Page

Источник

Читайте также:  Python openpyxl прочитать строку
Оцените статью