-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordValidator.java
More file actions
53 lines (53 loc) · 1.29 KB
/
PasswordValidator.java
File metadata and controls
53 lines (53 loc) · 1.29 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
/* Password validator is a program that validates passwords to match specific rules. For example, the minimum length of the password must be eight characters long and it
should have at least one uppercase letter in it.
A valid password is the one that conforms to the following rules:
- Minimum length is 5;
- Maximum length is 10;
- Should contain at least one number;
- Should contain at least one special character (such as &, +, @, $, #, %, etc.);
- Should not contain spaces.
*/
import java.util.*;
public class PasswordValidator{
public static void main(String[] args){
Scanner in=new Scanner(System.in);
System.out.println("Enter your password for Validation");
String input=in.nextLine();
char ch[]=input.toCharArray();
int space=0,num=0,spec=0,word=0;
if(ch.length>=5&&ch.length<=10)
{
for(int i=0;i<ch.length;i++)
{
if(ch[i]==' ')
{
space++;
}
else if(Character.isDigit(ch[i]))
{
num++;
}
else if(ch[i]>='a'&&ch[i]<='z'||ch[i]>='A'&&ch[i]<='Z')
{
word++;
}
else
{
spec++;
}
}
if(space!=0||num==0||spec==0)
{
System.out.println("False");
}
else
{
System.out.println("True");
}
}
else
{
System.out.println("False");
}
}
}