-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordLockout.java
More file actions
65 lines (57 loc) · 2.77 KB
/
PasswordLockout.java
File metadata and controls
65 lines (57 loc) · 2.77 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
61
62
63
64
65
//This program will use a combination of facial recognition and keystroke dynamics to detect how fast a user inputs a password on Android.
import java.util.*;
public class PasswordLockout {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//Stores the average time it takes to enter password
double averageTime = 0;
//Stores the number of attempts to enter password
int attemptCount = 0;
//Stores the number of attempts that are allowed before lockout
int lockoutAttempts = 5;
System.out.println("Please enter your password: ");
//Get the time at which the user begins inputting the password
long startTime = System.currentTimeMillis();
String inputPassword = scanner.nextLine();
//Get the time at which the user ends inputting the password
long endTime = System.currentTimeMillis();
//Calculate the average time it takes to enter the password
averageTime = (endTime - startTime) / attemptCount;
attemptCount++;
//Check if the user has entered the correct password
if (isPasswordCorrect(inputPassword)) {
System.out.println("Password accepted!");
} else {
//Check if the user has exceeded the lockout attempts
while (attemptCount < lockoutAttempts) {
System.out.println("Incorrect password. Please try again: ");
//Get the time at which the user begins inputting the password
startTime = System.currentTimeMillis();
inputPassword = scanner.nextLine();
//Get the time at which the user ends inputting the password
endTime = System.currentTimeMillis();
//Calculate the average time it takes to enter the password
averageTime = (endTime - startTime) / attemptCount;
attemptCount++;
//Check if the user has entered the correct password
if (isPasswordCorrect(inputPassword)) {
System.out.println("Password accepted!");
break;
}
}
//Lockout the user if they have exceeded the lockout attempts
if (attemptCount == lockoutAttempts) {
System.out.println("You have exceeded the number of attempts. Your account is locked out.");
}
}
}
//Method to check if the password entered is correct
public static boolean isPasswordCorrect(String inputPassword) {
//Replace this with the actual password
String correctPassword = "password";
if (inputPassword.equals(correctPassword)) {
return true;
}
return false;
}
}