-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.h
97 lines (93 loc) · 2.87 KB
/
functions.h
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
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#ifndef PASSGEN_FUNCTIONS_H
#define PASSGEN_FUNCTIONS_H
#if defined(_WIN32)
#include <windows.h>
#elif defined(__APPLE__)
#include <ApplicationServices/ApplicationServices.h>
#elif defined(__linux__)
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <cstring>
#endif
#include <iostream>
#include <random>
#include "ostream"
#include "filesystem"
#include "string"
#include "fstream"
#include "ctime"
#include <chrono>
#include <algorithm>
#include <cctype>
#include <unordered_map>
using namespace std;
#define Fast std::ios_base::sync_with_stdio(false);
#define Srengine default_random_engine engine (seed());
random_device seed;
inline string getCurrentTime() {
chrono::system_clock::time_point now = chrono::system_clock::now();
time_t currentTime = chrono::system_clock::to_time_t(now);
tm* timeInfo = localtime(¤tTime);
ostringstream time;
time << setfill('0');
time << setw(2) << timeInfo->tm_hour << ":"<< setw(2) << timeInfo->tm_min << ":"
<< setw(2) << timeInfo->tm_sec;
return time.str();
}
inline string hardPass(short numOfChars){
Srengine
uniform_int_distribution<short> randomInt(33,126);
string pass;
for(short i =0;i<numOfChars;i++){
pass += static_cast<char>(randomInt(engine));
}
return pass;
}
inline string midPass(short numOfChars){
Srengine
uniform_int_distribution<short>randomInt1(48,57);
uniform_int_distribution<short>randomInt2(97,100);
string pass;
int rem = numOfChars - (numOfChars / 2);
for(short i = 0 ; i < numOfChars / 2 ; i++){
pass += static_cast<char>(randomInt1(engine));
}
for(int i = 0; i < rem ; i++){
pass+=static_cast<char>(randomInt2(engine));
}
return pass;
}
inline string ezPass(short numOfChars){
Srengine
uniform_int_distribution<short>randomInt1(48,53);
uniform_int_distribution<short>randomInt2(56,57);
string pass;
int rem = numOfChars - (numOfChars / 2);
for(short i = 0 ; i <numOfChars / 2 ; i++){
pass += static_cast<char>(randomInt1(engine));
}
for(int i = 0; i < rem ; i++){
pass+=static_cast<char>(randomInt2(engine));
}
return pass;
}
inline void writeToFile(const string& name,const string& password,const string& fileName){
filesystem::path currentPath = filesystem::current_path();
#if defined (__linux__)
string path = currentPath.string()+"/"+fileName;
#elif defined(_WIN32)
string path = currentPath.string()+"\\"+fileName;
#elif defined (__APPLE__)
string path = currentPath.string()+"/"+fileName;
#endif
ofstream vault(path, ios::app);
if(vault.is_open()){
vault<< name <<" " << password << " Generated at=>> "<<getCurrentTime()<<endl;
vault.close();
cout<<"---Successful---";
}
else
cout<<"***Failed to Open/Create: "<<fileName<<"***";
}
#endif