1. 程式人生 > >隨機密碼生成器randcodeR.v.0.4(Beta)正式釋出

隨機密碼生成器randcodeR.v.0.4(Beta)正式釋出

Readme: 按照相應規則生成隨機密碼, 可作為定期修改密碼的生成器, 避免了長期使用相同密碼造成的資訊洩露問題, 製作了一個較為初級的入門款軟體, 並貼出原始碼方便大家加入或使用自己的生成規則. 本人能力有限, 若是有技術上的不足也請大牛們指正, 謝謝!

  • Project: randcodeR
  • Language: C/C++
  • Auther: ZhuXiong
  • Version: v.0.4(beta)
  • Time: 2018.10.14 13:52(Shanghai Time)
  • Description:
    1. Structral improvements.
    1. Add save model. You can use it to save your random passwords in case of forgetting your passwords.
    1. Eazier operation. Add more hints and go back options.

== GitHub專案將會持續更新 敬請期待 ==

捐助地址: paypal.me/dolorhunter
下載地址: https://github.com/DolorHunter/randcodeR

在此感謝Huang的技術支援!

#目前最新的穩定版本v.0.4
#v.0.4持續優化中!


#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include"rand_num_type.h"
#include"rand_en_num_type.h"
#include"rand_en_num_pro_type.h"
#include"rand_expert.h"


using namespace std;

void creat_warehouse
(FILE *); void open_warehouse(FILE *, char [6]); void set_password(FILE *, char [6]); void save_warehouse(FILE *, char [80]); int main(void) { int bit; //位數 char code[10][80]={0}; char code_chose[80]={0}; char password[6]={0}; FILE *fp; creat_warehouse(fp);//密碼庫初始化(防止寫入失敗) indexpage: //goto回到主介面 cout << "===隨機密碼生成器===\n" << endl; cout << "\t\t\t\tBy:Zhuxiong\n" << endl; cout << "-[注意] 第一次使用請先設定密碼庫密匙!\t(0.密碼庫 -> 1.設定密碼)\n" << endl; cout << "選擇密碼生成規則:\n" << endl; cout << "0.密碼庫\n" << endl; cout << "1.純數字\n" << endl; cout << "2.數字+英文小寫\n" << endl; cout << "3.數字+英文混拼\n" << endl; cout << "4.專家\n" << endl; cout << "5.撒幣支援!\n" << endl; cout << "請輸入序號:" << endl; int rules; cin >> rules; system("CLS"); srand((int)time(0)); if(rules < 0 || rules > 5) { cout << "使用的規則錯誤!" << endl; return -1; } else { if(!rules) //0.密碼庫 { warehouse: //回到密碼庫 cout << "-[注意] 第一次使用請先設定密碼庫密匙!\t(0.密碼庫 -> 1.設定密碼)\n" << endl; cout << "0.開啟密碼庫\n" << endl; cout << "1.設定密碼\n" << endl; cout << "2.忘記密碼\n" << endl; cout << "3.返回主介面\n" << endl; cout << "請輸入序號:" << endl; int chose; cin>>chose; system("CLS"); if(chose < 0 || chose > 3) { cout << "使用的規則錯誤!" << endl; exit(1); } else { if(!chose) //0.開啟密碼庫 { open_warehouse(fp, password); system("CLS"); goto warehouse; } else if(chose == 1) //1.設定密碼 { set_password(fp, password); system("CLS"); goto warehouse; } else if(chose == 2) //2.忘記密碼 { cout << "-[聯絡作者]:\n-Telegram:Zhuxiong\n-Mail:[email protected]\n" << endl; cout << "0.強制改密\t[特別注意]: 此操作會刪除所有儲存密碼且不可恢復!\n" <<endl; cout << "1.返回上級\n" << endl; int chose1; cin>>chose1; if(!chose1) //0.強制改密 { system("CLS"); set_password(fp, password); system("CLS"); goto warehouse; } else //1.返回上級 { system("CLS"); goto warehouse; } } else //3.返回主介面 { system("CLS"); goto indexpage; } } } else if(rules != 5) //1~4生成密碼 { cout << "請輸入密碼位數:" << endl; cin >> bit; cout << "\n" << endl; int judge; do //迴圈生成密碼 { if(rules==1) { rand_num_type(bit, code); //純數字 } else if(rules==2) { rand_en_num_type(bit, code); //英文+數字 } else if(rules==3) { rand_en_num_pro_type(bit, code); //英文大小寫+數字 } else { rand_expert( bit, code); //ascii隨機 } cout << "請輸入選擇本輪密碼的序號, 若不選擇請輸入其他字元." << endl; cin >> judge; if(judge >=0 && judge <=9) //選中生成密碼 { for(int i=0;i<bit;i++) { code_chose[i] = code[judge][i]; code_chose[i+1]='\0'; } save_warehouse(fp, code_chose); judge = 0; //重置判定引數 } else { system("pause"); judge = 1; } } while(judge == 1); system("CLS"); goto indexpage; } else //5.捐助 { cout << "感謝您的所有認可和捐助!\n" << endl; cout << "-[聯絡作者]:\nTelegram:Zhuxiong\nMailBox:[email protected]\n" << endl; cout << "-[捐助地址]: paypal.me/dolorhunter\n" << endl; cout << "再次感謝您的認可和捐助!\n" << endl; cout << "\n#輸入0返回主介面\n" << endl; int temp; cin >> temp; if(!temp) { system("CLS"); goto indexpage; } } } return 0; } void creat_warehouse(FILE *fp) { if(fp = fopen("CodeX.dat", "ab")) { ; } else { printf("CANNOT NEW\n");//容錯處理 exit(1); } fclose(fp); } void open_warehouse(FILE *fp, char *password)//讀取檔案首行 比對密碼是否相同 { char buff[4096]; char inp_code[6]; char tbuff[6]; if(fp = fopen("CodeX.dat", "rb")) { cout << "請輸入密碼庫密碼:" << endl; cin >> inp_code; fread(tbuff, 6*sizeof(char), 1, fp); while(true) { bool correct=true; for(int i=0;i<6;i++){ if(tbuff[i]!=inp_code[i]){ correct=false; } } if(correct) { printf("密碼正確!\n"); fseek(fp,6,SEEK_SET); fread(buff, 4096*sizeof(char), 1, fp); cout << buff << endl; cout << "輸入回車返回上一級"<< endl; getchar(); getchar(); break; } else { cout << "密碼錯誤!請重新輸入:" << endl; cin >> inp_code; } } } else { printf("CANNOT OPEN\n");//容錯處理 exit(1); } fclose(fp); } void set_password(FILE *fp, char *password) { cout << "-[警告] 開啟密碼庫的密碼請勿遺失, 若遺失將無法開啟加密庫!\n" << endl; cout << "輸入6位數字密碼作為開啟加密庫的鑰匙:" << endl; cin>>password; if(fp = fopen("CodeX.dat", "wb")) { fprintf(fp, "%s\n", password); } else { printf("CANNOT OPEN\n");//容錯處理 exit(1); } fclose(fp); } void save_warehouse(FILE *fp, char *code_chose) { cout <<"-正在將密碼存入密碼庫.." << endl; if(fp = fopen("CodeX.dat", "ab")) { fprintf(fp, "網站, 密碼\n"); cout << "輸入網站地址以備註:" << endl; char webInf[80]={0}; cin >> webInf; fprintf(fp, "%s, %s\n", webInf, code_chose); } else { printf("CANNOT OPEN\n");//容錯處理 exit(1); } fclose(fp); }
		#rand_num_type.h


#pragma once

void rand_num_type(int bit, char (&code)[10][80])
{


    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';
        }

        std::cout << i << "\t" << code[i] << std::endl;
    }
}
		#rand_en_num_type.h

 #pragma once

 void rand_en_num_type(int bit, char (&code)[10][80])
{


    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';
            }
        }

        std::cout << i << "\t" << code[i] << std::endl;
    }
}

		#rand_en_num_pro_type.h

#pragma once

void rand_en_num_pro_type(int bit, char (&code)[10][80])
{


    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';
                }
        }

        std::cout << i << "\t" << code[i] << std::endl;
    }
}

		#rand_expert.h

#pragma once

void rand_expert( int bit, char (&code)[10][80])
{


    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';
        }

        std::cout << i << "\t" << code[i] <<std::endl;
    }
}

								Copyright:dolor_059