randcodeR燃灯计划(v.0.5)已在GitHub正式上线!!
谢谢大家的耐心等待本次很久没更的版本升级!!
Readme:
本程序可以按照相应规则生成随机密码. 可以避免了长期使用相同密码造成的信息泄露问题. 同时为了方便大家使用加入了将随机生成的密码保存于本地的功能. 在此贴出源码方便大家加入或使用自己的生成规则.
因为本人能力有限, 若是有技术上的不足也请大牛们指正, 谢谢!
- Project: randcodeR(燃灯计划)
- Language: C/C++
- Auther: ZhuXiong
- Version: v.0.5
- Time: 2018.12.04 14:24(Shanghai Time)
- Description:
-
- Rewriting basic structure and renew the menus.
-
- Redefine some constant in software, which makes the entire software more stable.
-
- Some bugs are detected but it will do no harm to regular use. I am gonna fix it later.
== GitHub项目将会持续更新 敬请期待 ==
- Some bugs are detected but it will do no harm to regular use. I am gonna fix it later.
捐助地址: paypal.me/dolor059
下载地址: https://github.com/DolorHunter/randcodeR
粘几个头文件的代码上来
# 目前最新的稳定版本v.0.5
# v.0.5持续优化中!
# 感谢你的使用!
#file lib.h
#pragma once
#include<cstdlib>
#include<iostream>
#include"animation.h"
using namespace std;
void creatLib(FILE *fp)
{
if(fp = fopen("CodeX.dat", "ab"))
{
;
}
else
{
printf("CANNOT NEW .dat.\n");//容错处理
exit(1);
}
fclose(fp);
}
void openLib(FILE *fp, const char *password)//读取文件首行 比对密码是否相同
{
char buff[4096];
char inp_code[6];
char tbuff[6];
if(fp = fopen("CodeX.dat", "rb"))
{
cout << "请输入密码库密码:" << endl;
cin >> inp_code;
cin.get();
fread(tbuff, 6*sizeof(char), 1, fp);
while(true)
{
bool sign=true;
for(int i=0;i<6;i++){
if(tbuff[i]!=inp_code[i]){
sign=false;
}
}
if(sign)
{
cout << "密码正确!" << endl;
fseek(fp,6,SEEK_SET);
fread(buff, 4096*sizeof(char), 1, fp);
cout << "-----------------以下是密码-----------------" << endl;
cout << buff << endl;
cout << "--------------------------------------------" << endl;
cout << "输入回车返回上一级"<< endl;
getchar();
getchar();
break;
}
else
{
cout << "密码错误!请重新输入:" << endl;
cin >> inp_code;
cin.get();
}
}
}
else
{
printf("CANNOT OPEN\n");//容错处理
exit(1);
}
fclose(fp);
}
void setLibPassword(FILE *fp, char *password)
{
cout << "-[警告] 打开密码库的密码请勿遗失, 若遗失将无法开启加密库!\n" << endl;
cout << "输入6位数字密码作为打开加密库的钥匙:" << endl;
cin>>password;
cin.get();
if(fp = fopen("CodeX.dat", "wb"))
{
fprintf(fp, "%s\n", password);
}
else
{
printf("CANNOT OPEN\n");//容错处理
exit(1);
}
fclose(fp);
}
void saveToLib(FILE *fp, char *codeChose)
{
cout <<"-正在将密码存入密码库.." << endl;
if(fp = fopen("CodeX.dat", "ab"))
{
fprintf(fp, "网站, 密码\n");
cout << "输入网站地址以备注:" << endl;
char webInf[80]={0};
cin >> webInf;
cin.get();
fprintf(fp, "%s, %s\n", webInf, codeChose);
saving(); //正在保存(动画)
}
else
{
printf("CANNOT OPEN\n");//容错处理
exit(1);
}
fclose(fp);
}
# 目前最新的稳定版本v.0.5
# v.0.5持续优化中!
# 感谢你的使用!
#file creadCode.h
#pragma once
#include<iostream>
#include"codeRules.h"
#include"lib.h"
#define MAXLEN 1024
void creatCode(FILE *fp, const int &rules){
char code[10][MAXLEN]={0};
char codeChose[MAXLEN]={0};
int bit;
cout << "请输入密码位数:" << endl;
cin >> bit;
cin.get();
int judge; //判断是否保存
cout << "\n" << endl;
do{ //循环生成密码
switch(rules){
case 1:
rand_num(bit, code); break; //纯数字
case 2:
rand_en_num(bit, code); break; //英文+数字
case 3:
rand_en_num_pro(bit, code); break; //英文大小写+数字
case 4:
rand_expert(bit, code); break; //ascii随机
default:
break;
}
cout << "请输入选择本轮密码的序号, 若不选择请输入字母或符号." << endl;
cin >> judge;
cin.get();
if(judge >=0 && judge <=9) //选中生成密码
{
for(int i=0; i<bit; i++)
{
codeChose[i] = code[judge][i];
codeChose[i+1]='\0';
}
saveToLib(fp, codeChose); //保存密码与密码库
judge = 0; //重置判定参数
}
else
{
judge = 1;
}
}while(judge == 1);
}
# 目前最新的稳定版本v.0.5
# v.0.5持续优化中!
# 感谢你的使用!
#file codeRules.h
#pragma once
#include<iostream>
#define MAXLEN 1024
using namespace std;
//数字
void rand_num(const int bit, char (&code)[10][MAXLEN])
{
for(int i=0;i<10;i++)
{
for(int j=0;j<bit;j++)
{
code[i][j] = rand()%10+'0'-0;
code[i][j+1] = '\0';
}
cout << i << "\t" << code[i] << endl;
}
}
//数字+英文小写
void rand_en_num(const int bit, char (&code)[10][MAXLEN])
{
for(int i=0;i<10;i++)
{
for(int j=0;j<bit;j++)
{
if(rand()%2==0)
{
code[i][j] = rand()%10+'0'-0;
code[i][j+1] = '\0';
}
else
{
code[i][j] = rand()%26 + 97;
code[i][j+1] = '\0';
}
}
cout << i << "\t" << code[i] << endl;
}
}
//数字+英文大小写
void rand_en_num_pro(const int bit, char (&code)[10][MAXLEN])
{
for(int i=0;i<10;i++)
{
for(int j=0;j<bit;j++)
{
if(rand()%3==0)
{
code[i][j] = rand()%10+'0'-0;
code[i][j+1] = '\0';
}
else
if(rand()%3==1)
{
code[i][j] = rand()%26 + 65;
code[i][j+1] = '\0';
}
else
{
code[i][j] = rand()%26 + 97;
code[i][j+1] = '\0';
}
}
cout << i << "\t" << code[i] << endl;
}
}
//专家(字符型)
void rand_expert(const int bit, char (&code)[10][MAXLEN])
{
for(int i=0;i<10;i++)
{
for(int j=0;j<bit;j++)
{
code[i][j] = rand()%95 + 32;
code[i][j+1] = '\0';
}
cout << i << "\t" << code[i] <<endl;
}
}
Copyright: dolor_059