老是需要改密码, 所以自己写个生成器, 会生成很复杂的密码, 并记录在文件里面
输出
代码
#include <iostream>
#include <fstream>
#include <random>
#include <unistd.h>
using namespace std;
static std::string base = "qwertyuiopasdfghjklzxcvbnm1234567890%-+=,./?:;'@!^$&()[]{}";
const int MAX_PATH = 250;
const int SIZE = 30;
const int BS = SIZE / 3;
std::string getCurrentDir() {
char buffer[MAX_PATH];
getcwd(buffer, MAX_PATH);
return buffer;
}
long long getDate() {
time_t t = time(nullptr);
char tmp[64];
strftime( tmp, sizeof(tmp), "%Y%m%d",localtime(&t) );
return strtol(tmp, nullptr, 10);
}
void generate2(int n, long long date, int time, const char* description = "默认") {
std::string dir = getCurrentDir() + "/passwd";
std::string path = dir + "_" + to_string(date) + "_" + to_string(time);
cout << path << endl;
ofstream fs(path);
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dis(0, base.size() - 1);
std::string pd;
for (int i = 0; i < n; i++) {
char c = base[dis(mt)];
if (dis(mt) % BS == 0) {
c = (char)toupper(c);
}
pd.push_back(c);
}
if (description) {
fs << "描述: " << description << endl;
cout << "描述: " << description << endl;
}
cout << "密码: " << pd << endl;
fs << "密码: " << pd;
}
int main() {
generate2(SIZE, getDate(), time(nullptr), "王者荣耀密码");
return 0;
}
|