-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassword_generator.cpp
75 lines (62 loc) · 1.47 KB
/
Password_generator.cpp
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
/*
Strong Password generatro.
Created for everyone,By mortzaCFT
Copyright: free for anychanges.
*/
#include <iostream>
#include <string>
#include <cctype>
#include <random>
bool contains_upper(const std::string& password)
{
for (char c : password)
{
if (std::isupper(c))
{
return true;
}
}
return false;
}
bool contains_symbols(const std::string& password)
{
for (char c : password)
{
if (ispunct(c))
{
return true;
}
}
return false;
}
std::string generate_password(int length, bool symbols, bool uppercase)
{
std::string combination = "abcdefghijklmnopqrstuvwxyz0123456789";
if (symbols)
{
combination += "!@#$%^&*()_-+=<>?/{}[]";
}
if (uppercase)
{
combination += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, combination.length() - 1);
std::string new_password;
for (int i = 0; i < length; ++i)
{
new_password += combination[dis(gen)];
}
return new_password;
}
int main()
{
for (int i = 1; i <= 5; ++i)
{
std::string new_pass = generate_password(15, true, true);
std::string specs = "U: " + std::to_string(contains_upper(new_pass)) + ", S: " + std::to_string(contains_symbols(new_pass));
std::cout << i << " -> " << new_pass << " (" << specs << ")\n";
}
return 0;
}