-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordStrength.java
More file actions
60 lines (59 loc) · 1.45 KB
/
PasswordStrength.java
File metadata and controls
60 lines (59 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Write a program to check the Strength of the password.
*/
import java.util.*;
public class PasswordStrength{
public static void main(String[] args){
Scanner in=new Scanner(System.in);
System.out.println("Enter Your Password");
String input=in.nextLine();
char ch[]=input.toCharArray();
int upper=0,lower=0,num=0,spec=0,space=0;
for(int i=0;i<ch.length;i++)
{
if(ch[i]==' ')
{
space++;
}
else if(ch[i]>='A' && ch[i]<='Z')
{
upper++;
}
else if(ch[i]>='a' && ch[i]<='z')
{
lower++;
}
else if(Character.isDigit(ch[i]))
{
num++;
}
else
{
spec++;
}
}
if(space!=0)
{
System.out.println("A password cannot have a space");
}
else if(((upper>=1&&lower>=1)&&(num>=1&&spec>=1))&&ch.length>=8)
{
System.out.println("Password Strength:Great!");
}
else if((upper>=1&&lower>=1)&&(num>=1&&spec>=1))
{
System.out.println("Password Strength:Good");
}
else if(((upper>=1&&lower>=1)&&num>=1)||((upper>=1&&lower>=1)&&spec>=1)||((upper>=1&&num>=1)&&spec>=1)||((lower>=1&&num>=1)&&spec>=1))
{
System.out.println("Password Strength:Ok Ok");
}
else if((upper>=1&&lower>=1)||(upper>=1&&num>=1)||(upper>=1&&spec>=1)||(lower>=1&&num>=1)||(lower>=1&&spec>=1)||(num>=1&&spec>=1))
{
System.out.println("Password Strength:Weak");
}
else
{
System.out.println("Password Strength:Very Weak!");
}
}
}