前言
最近在使用Edge浏览器时候,发现在密码中有几个已经泄露的密码!!
但还好不是重要的密码,不然~~~你懂得
所以我首次启发,编写了一个生成强密码的c++程序,代码自取
正文
程序其实原理很简单:
获得事件(用户想要什么类型的强密码)
获取随机数来随机组合数字、字母、特殊符号
将生成的强密码储存进TXT文本中
下面是代码:(注释部分是秘钥机制,可自行更改)
#include<bits/stdc++.h>
#include<Unistd.h>//Sleep() 函数
#include<fstream>//文件读入输出头文件
#include<ctime>
#include<windows.h>
using namespace std;
char* eng[14]={"hello","you","my","youtobe","Google","duck","English","test","txt","ball","flower","bird","dog","snake"};
char sf[26]={'~','!','@','#','$','%','^','&','*','_','+','-','=','/','(',')','{','}',';',':','[',']','<','>',',','.'};
void test(){
ofstream ofs;
ofs.open("Key.txt",ios::out );
//加了个for循环去将第一列写成全部Q,第二列写成123...
ofs << "1V]7y#2G^8j=2Q{0t<3A~1e&4K+2o}5U[2x@6F%3i-6P)4s]7Y,5d^8J_6n{0T:6w!1E$7h+1O(8r[2X>0c%3I*1m)4S;1v~5D#2"; //endl用于换行
ofs.close();
}
int shencheng(int a,int b){
const int seq_int = b;//定义一个常量值为41
int timePassword = 0;//用来存放随机数
srand((unsigned int)time(NULL));//srand中的参数就是seed,也就是随机数将会在0~(seed-1)中进行产生
timePassword = rand() % seq_int + a;//产生a~seq_int以内的数据
return timePassword;
}
bool temp1(){
int temp,temp1,temp2;
printf("强密码位数:");
cin>>temp;//获得强密码位数
printf("要在密码里加入那些元素?\n");
printf("1.数字+字母大小写\n2.特殊字符\n请输入数字(1表示选第一个,2表示全选)");
cin>>temp1;
printf("要生成几个强密码?");
cin>>temp2;
ofstream fout("Password.txt");
printf("\n生成时间可能较长请耐心等待····· 大约需要%d秒",temp/2*temp2);
int shuzi=0;
char zimu;
for(int i=0;i<temp2;i++){
string t1;
printf("\n给你的第%d个强密码取个名字吧:",i+1);
cin>>t1;
fout<<t1<<':'<<endl;
for(int j=0,t=0,t1=0;j<temp;j++){//生成密码
if(t==0){//数字
shuzi=int(shencheng(0,9));
fout<<shuzi;
}else{
if(t==1 && t1==0){//大写字母
shuzi=shencheng(1,25);
shuzi+=64;
zimu=shuzi;
fout<<zimu;
t1++;
}else{
if(t==1 && t1==1){//大写字母
shuzi=shencheng(1,25);
shuzi+=96;
zimu=shuzi;
fout<<zimu;
t1++;
}
}
}
if(t==2){
fout<<sf[shencheng(0,25)];
}
t++;
if(t>temp1){
t=0;
}
if(t1>1){
t1=0;
}
Sleep(500);
}
fout<<endl<<endl;
}
printf("\n强密码已生成在本程序目录下,请前去查看!\n");
printf("本程序由小小的博客编写,感谢使用!\n");
fout.close();
system("pause");
}
bool temp2(){
int shuzi,temp;
ofstream fout("Password.txt");
printf("输入一个你喜欢的数字:");
cin>>shuzi;
printf("\n生成时间可能较长请耐心等待····· 大约需要%d秒",temp/2);
for(int i=1;i<=7;i++){
if(i%2==0){
fout<<shuzi;
}else{
temp=shencheng(0,13);
fout<<eng[temp];
}
Sleep(500);
}
printf("\n强密码已生成在本程序目录下,请前去查看!\n");
printf("本程序由小小的博客编写,感谢使用!\n");
fout.close();
system("pause");
}
int main(){
// string a="123qweasd",b,c;
// char line[5];//字符数组,用于读取,这里假设每次读取的整数不超过4个字符
// int num[10];
// int i = 0;
// ifstream infile;
// infile.open("Key.txt");//打开文件
// if (!infile.is_open())
// {
// cout << "秘钥文件有误!" << endl;
// ofstream ofs;
// ofs.open("Key.txt",ios::out );
//
// ofs << "1"; //endl用于换行
// ofs.close();
// }
// while (infile >> c)
// {
//
// i++;
// }
// infile.close();//关闭文件
// if(c!="1V]7y#2G^8j=2Q{0t<3A~1e&4K+2o}5U[2x@6F%3i-6P)4s]7Y,5d^8J_6n{0T:6w!1E$7h+1O(8r[2X>0c%3I*1m)4S;1v~5D#2"){
// cout<<"请输入秘钥:";
// cin>>b;
// if(a!=b){
// cout<<"错误!正在退出!";
// Sleep(2000);
// return 0;
// }else{
// test();
// }
// }
while(true){
printf("1.随机生成强密码\n2.容易记的强密码(相对第一种弱些)\n你要什么类型的强密码?(输入数字)");
int temp;
cin>>temp;//获得事件
// cout<<endl<<temp;
system ("cls");
if(temp==1){
temp1();
}
if(temp==2){
temp2();
}
system ("cls");
}
return 0;
}
如果你喜欢我写的程序可以点个赞哦!