-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_capture.py
More file actions
86 lines (67 loc) · 2.18 KB
/
verify_capture.py
File metadata and controls
86 lines (67 loc) · 2.18 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import time
import threading
from pynput.keyboard import Controller, Key
from src.capture import KeystrokeCapture
def run_test():
print("Test 1: Correct Password 'test'")
capture = KeystrokeCapture("test")
# Start capture in a thread so we can type
t = threading.Thread(target=capture.start_capture)
t.start()
# Give it a moment to start
time.sleep(0.5)
keyboard = Controller()
# Simulate typing "test"
for char in "test":
keyboard.press(char)
time.sleep(0.1) # Dwell
keyboard.release(char)
time.sleep(0.1) # Flight
keyboard.press(Key.enter)
keyboard.release(Key.enter)
t.join()
if capture.validate_sample():
print(" -> Validation PASSED")
else:
print(" -> Validation FAILED")
dwells, flights, total = capture.extract_features()
print(f" -> Dwells: {dwells}")
print(f" -> Flights: {flights}")
print(f" -> Total Time: {total}")
if len(dwells) == 4 and len(flights) == 3:
print(" -> Feature Count PASSED")
else:
print(" -> Feature Count FAILED")
print("\nTest 2: Incorrect Password 'tset'")
capture = KeystrokeCapture("test")
t = threading.Thread(target=capture.start_capture)
t.start()
time.sleep(0.5)
for char in "tset":
keyboard.press(char)
time.sleep(0.05)
keyboard.release(char)
time.sleep(0.05)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
t.join()
if not capture.validate_sample():
print(" -> Rejection PASSED (Expected Failure)")
else:
print(" -> Rejection FAILED (Should have failed)")
print("\nTest 3: Backspace Usage")
capture = KeystrokeCapture("test")
t = threading.Thread(target=capture.start_capture)
t.start()
time.sleep(0.5)
keyboard.press('t')
keyboard.release('t')
keyboard.press(Key.backspace)
keyboard.release(Key.backspace)
t.join() # Listener should stop on backspace
if capture.aborted:
print(" -> Backspace Rejection PASSED")
else:
print(" -> Backspace Rejection FAILED")
if __name__ == "__main__":
run_test()