c++-密码生成小程序
生活随笔
收集整理的這篇文章主要介紹了
c++-密码生成小程序
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
老是需要改密碼, 所以自己寫個(gè)生成器, 會(huì)生成很復(fù)雜的密碼, 并記錄在文件里面
輸出
代碼
#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 = "默認(rèn)") {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; }總結(jié)
以上是生活随笔為你收集整理的c++-密码生成小程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CAPL基础知识学习
- 下一篇: s3c2440移植MQTT