Skip to content

Password Strength in Java #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Java/Password_Strength/PasswordStrength.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package password;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PasswordStrength {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the password:");
String password = sc.next();
check(password);
}

public static void check(String password) {
// TODO Auto-generated method stub
// ^ represents the starting of the string.
// (?=.*[a-z]) represent at least one lowercase character.
// (?=.*[A-Z]) represents at least one uppercase character.
// (?=.*\\d) represents at least one numeric value.
// (?=.*[-+_!@#$%^&*., ?]) represents at least one special character.
// . represents any character except line break.
// + represents one or more times.
String regex = "^(?=.*[a-z])(?=."+ "*[A-Z])(?=.*\\d)"+ "(?=.*[-+_!@#$%^&*., ?]).+$";

// Compile the ReGex
Pattern pattern = Pattern.compile(regex);

// if the string entered is null then the output will be password invalid
if (password == null) {
System.out.println("Password Invalid.");
return;
}

// Find match between given string & regular expression
Matcher matcher = pattern.matcher(password);

if (matcher.matches())
System.out.println("Password Valid and Strong.");
else
System.out.println("Weak Password.");
}

}
18 changes: 18 additions & 0 deletions Java/Password_Strength/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Password Strength

A program to check the strength of the password . For a strong password, the password must contain a mixture of upper case letters, a digit (including 0-9), and special characters with lower case letters.

## Sample Input
Sapna123@

## Sample Output
Password Valid and Strong.

## Screenshot
![demo](https://user-images.githubusercontent.com/56690856/98788220-90b3ed00-2426-11eb-94e6-c9115c61eebf.png)

## Time Complexity
O(N)

## Space Complexity
O(1)