forked from parakramgambhir14/CryptVault
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.cpp
More file actions
75 lines (51 loc) · 1.6 KB
/
auth.cpp
File metadata and controls
75 lines (51 loc) · 1.6 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
#include "auth.h"
#include "../utils/config.h" // access stored password, attempts, timestamp
#include <iostream>
using namespace std;
// ================= CHECK FIRST RUN =================
// If no password exists → system not initialized yet
bool isFirstRun() {
return getStoredPassword().empty();
}
// ================= FIRST RUN SETUP =================
void firstRunSetup() {
string pwd;
cout << "Set Master Password: ";
cin >> pwd;
// Store password in config
setPassword(pwd);
// Initialize attempts to 0
setAttempts(0);
// Store current time for expiry tracking
setTimestamp();
// Save everything to config.txt
saveConfig();
cout << "Setup complete.\n";
}
// ================= LOGIN FUNCTION =================
LoginResult login() {
string input;
cout << "Enter Password: ";
cin >> input;
// ===== CORRECT PASSWORD =====
if (input == getStoredPassword()) {
// Reset failed attempts (important security fix)
setAttempts(0);
saveConfig();
return REAL_USER;
}
// ===== WRONG PASSWORD =====
else {
cout << "Access granted.\n";
// ⚠️ intentional deception (do NOT say "wrong password")
// Increment failed attempts
incrementAttempts();
saveConfig();
// ===== CHECK MAX ATTEMPTS =====
if (getAttempts() >= 3) {
return BLOCKED; // triggers self-destruct in main
}
// Otherwise → open decoy vault
return DECOY_USER;
}
}