forked from parakramgambhir14/CryptVault
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecurity.cpp
More file actions
70 lines (55 loc) · 1.66 KB
/
security.cpp
File metadata and controls
70 lines (55 loc) · 1.66 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
#include "security.h"
#include "../utils/config.h" // for timestamp access
#include <ctime>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <iostream>
using namespace std;
// ================= SELF-DESTRUCT =================
void destroyVault() {
// Deletes real vault and config
remove("data/vault.txt");
remove("data/config.txt");
cout << "💣 Vault permanently destroyed!\n";
}
// ================= EXPIRY CHECK =================
void checkExpiry() {
time_t now = time(0);
// getTimestamp() returns creation time from config
time_t created = getTimestamp();
if (created != 0 && (now - created > 86400)) { // 24 hours
cout << "⏳ Vault expired. Triggering self-destruct...\n";
destroyVault();
exit(0); // terminate program immediately
}
}
// ================= ENCRYPTION (SHIFT CIPHER) =================
string encrypt(string s) {
for(char &c : s) {
c += 2; // simple +2 shift
}
return s;
}
string decrypt(string s) {
for(char &c : s) {
c -= 2; // reverse shift
}
return s;
}
// ================= PASSWORD STRENGTH =================
int passwordStrength(string pwd) {
bool hasUpper = false, hasLower = false, hasDigit = false, hasSpecial = false;
for(char c : pwd) {
if(isupper(c)) hasUpper = true;
else if(islower(c)) hasLower = true;
else if(isdigit(c)) hasDigit = true;
else hasSpecial = true;
}
int score = 0;
if(hasUpper) score++;
if(hasLower) score++;
if(hasDigit) score++;
if(hasSpecial) score++;
return score; // 1-4
}