-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment2_2211063042.java
More file actions
52 lines (41 loc) · 1.54 KB
/
Assignment2_2211063042.java
File metadata and controls
52 lines (41 loc) · 1.54 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
import java.util.Scanner;
class InvalidPasswordException extends Exception {
String password;
InvalidPasswordException(String password) {
this.password = password;
}
public String toString() {
return "InvalidPasswordException: Invalid password format. Password: " + password;
}
}
public class Assignment2_2211063042 {
static void validatePassword(String password) throws InvalidPasswordException {
if (!password.matches("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).{6,}$")) {
throw new InvalidPasswordException(password);
} else {
System.out.println("Password is valid.");
System.out.println("Password " + password);
if (password.length() > 10) {
System.out.println("Password is too strong");
} else {
System.out.println("Passsword is not strong");
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the limit of input: ");
int input = scanner.nextInt();
scanner.nextLine();
for (int i = 0; i < input; i++) {
System.out.print("Enter a password: ");
String password = scanner.nextLine();
try {
validatePassword(password);
} catch (InvalidPasswordException e) {
System.out.println("Exception Caught: " + e);
}
}
scanner.close();
}
}