-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidUser.java
More file actions
61 lines (39 loc) · 1023 Bytes
/
ValidUser.java
File metadata and controls
61 lines (39 loc) · 1023 Bytes
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
61
package itransform;
import java.util.Scanner;
public class ValidUser {
public static boolean isValidUser(String s) {
if(s.isBlank() && !s.matches("^[a-zA-Z0-9_]+$") ) {
return false;
}
return true;
}
public static boolean isValidPass(String s) {
if (!s.matches(".*[A-Z].*") || !s.matches(".*[a-z].*") || !s.matches(".*\\d.*") || !s.matches(".*[^a-zA-Z\\d].*")) {
return false;
}
return true;
}
public static void main(String[] args) {
int attempts=0;
while(attempts<3) {
Scanner sc = new Scanner(System.in);
System.out.println("Username: ");
String user = sc.nextLine();
System.out.println("Password: ");
String password = sc.nextLine();
if(isValidUser(user)&&isValidPass(password)) {
System.out.println("welcome");
break;
}
else {
attempts++;
if(attempts==3) {
System.out.println("Contact Admin");
}
else {
System.out.println("try again");
}
}
}
}
}