自制密码生成器1.0
密码位数:1~50;
有多种复杂度;
附上C++代码:
#include<iostream>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<windows.h>
#include<time.h>
#define _for(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
char password[51]="";
bool f[4];
int n;
void color(int a);
void gotoxy(int x,int y);
bool copytoplate(const char* pszData);
void Initialize();
void main_interface();
void generate();
void gotoxy(int x,int y){//位置函数
COORD pos;
pos.X=2*x;
pos.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void color(int a){//颜色函数
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
bool copytoplate(const char* pszData){//复制字符串到剪贴板
const int nDataLen=strlen(pszData);
if(::OpenClipboard(NULL))
{
::EmptyClipboard();
HGLOBAL clipbuffer;
char *buffer;
clipbuffer = ::GlobalAlloc(GMEM_DDESHARE, nDataLen+1);
buffer = (char *)::GlobalLock(clipbuffer);
strcpy(buffer, pszData);
::GlobalUnlock(clipbuffer);
::SetClipboardData(CF_TEXT, clipbuffer);
::CloseClipboard();
return 1;
}
return 0;
}
void Initialize(){
system("color f0");
RECT rect;
HWND hwnd=GetForegroundWindow();
GetWindowRect(hwnd,&rect);
MoveWindow(hwnd,0,0,rect.right-rect.left,rect.bottom-rect.top,TRUE);
system("mode con cols=90 lines=30");
}
void enter(){
Initialize();
Sleep(500);
gotoxy(17,14);
printf("加载中…");
main_interface();
}
void main_interface(){
system("cls");
gotoxy(0,0);printf("密码位数(1~50):");
scanf("%d",&n);
if(n<1||n>50){
printf("\n超长!!!");
Sleep(1000);
main_interface();
}
PO:
system("cls");
gotoxy(0,0);printf("密码位数(1~50):%d",n);
printf("\n复杂度:");
printf("\n 1.数字 ");if(f[0])printf("\t√"); else printf("\t\t");
printf("\n 2.小写字母");if(f[1])printf("\t√"); else printf("\t\t");
printf("\n 3.大写字母");if(f[2])printf("\t√"); else printf("\t\t");
printf("\n 4.其他符号");if(f[3])printf("\t√\n"); else printf("\t\t\n");
char k=getch();
if(k=='1'){
f[0]=!f[0];
goto PO;
}else if(k=='2'){
f[1]=!f[1];
goto PO;
}else if(k=='3'){
f[2]=!f[2];
goto PO;
}else if(k=='4'){
f[3]=!f[3];
goto PO;
}else if(k==13)generate();
else goto PO;
printf("%s",password);
if(copytoplate(password))printf("\n已拷贝到剪贴板!");
system("pause");
}
void generate(){
const char p[]="`1234567890~-=@#$%^&*()_+qwertyuiop[]QWERTYUIOP{}|asdfghjkl;'ASDFGHJKL:zxcvbnm,./ZXCVBNM<>?";
int len=strlen(p);
_for(i,0,n){
srand((unsigned int)rand());
int l=rand()%len;
if(p[l]>='0'&&p[l]<='9'){
if(f[0])password[i]=p[l];
else i--;
}else if(p[l]>='a'&&p[l]<='z'){
if(f[1])password[i]=p[l];
else i--;
}else if(p[l]>='A'&&p[l]<='Z'){
if(f[2])password[i]=p[l];
else i--;
}else{
if(f[3])password[i]=p[l];
else i--;
}
}
}
int main(){
enter();
return 0;
}
注意:
生成完后,会自动复制到剪贴板!