-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_validator.cpp
More file actions
44 lines (36 loc) · 1.42 KB
/
password_validator.cpp
File metadata and controls
44 lines (36 loc) · 1.42 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
#include <iostream>
#include <regex>
#include <string>
using namespace std;
int main() {
cout << "Content-type:text/html\r\n\r\n";
string query;
getline(cin, query);
string key = "password=";
string password = "";
size_t pos = query.find(key);
if (pos != string::npos)
password = query.substr(pos + key.length());
// Decode '+' as space (optional improvement)
for (char &c : password)
if (c == '+') c = ' ';
// Regex for password validation (DFA equivalent)
regex pattern("^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[@#$%^&+=!]).{8,}$");
cout << "<html><body style='font-family:Arial;text-align:center;padding:20px;'>";
if (regex_match(password, pattern)) {
cout << "<h2 style='color:green;'>✅ Password is Valid!</h2>";
cout << "<p>Great! Your password meets all DFA and regex conditions.</p>";
} else {
cout << "<h2 style='color:red;'>❌ Invalid Password!</h2>";
cout << "<p>The password must include:</p>";
cout << "<ul style='text-align:left;display:inline-block;'>";
cout << "<li>At least 8 characters</li>";
cout << "<li>At least one uppercase letter</li>";
cout << "<li>At least one lowercase letter</li>";
cout << "<li>At least one digit</li>";
cout << "<li>At least one special character (@#$%^&+=!)</li>";
cout << "</ul>";
}
cout << "</body></html>";
return 0;
}