溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

利用C++怎么編寫一個密碼管理系統(tǒng)

發(fā)布時間:2020-11-30 15:59:26 來源:億速云 閱讀:953 作者:Leah 欄目:開發(fā)技術(shù)

利用C++怎么編寫一個密碼管理系統(tǒng)?針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

功能介紹:

1.怎么創(chuàng)建密碼,輸入兩次

2.怎么修改密碼

3.怎么刪除密碼

目錄

1.主界面

利用C++怎么編寫一個密碼管理系統(tǒng)

2. 功能代碼

利用C++怎么編寫一個密碼管理系統(tǒng)

利用C++怎么編寫一個密碼管理系統(tǒng)

利用C++怎么編寫一個密碼管理系統(tǒng)

是不是有點(diǎn)意思,那還不ctrl-c ctrl-v   弄入你的IDE環(huán)境下,試下

// mima.cpp: 主項目文件。
 
#include "stdafx.h"
 
///
 
#include <iostream>
#include <conio.h>
#include <string.h>
#include <fstream>
//#include <windows.h>
using namespace std;
void display(); //主界面函數(shù)
void xuanze(); //選擇函數(shù)
 
int read_file(); //讀取密碼文件
void write_file();//寫入密碼文件
void Create_mima(); //創(chuàng)建密碼
void YanZheng_mima(); //驗證密碼
void Chang_mima(); //修改密碼
void delete_mima(); //刪除密碼
//
 
void jiami_suanfa(char* str); //加密解密算法
 
char mimaStr[100]; //全局變量
//以上是函數(shù)的聲明部分
 
//下面是函數(shù)的實(shí)現(xiàn)部分
 
void display() //主界面函數(shù)
{
 system("cls");
 read_file();
 cout<<"\t\t************************************************"<<endl;
 cout<<"\t\t\t\t歡迎使console密碼系統(tǒng)"<<endl;
 cout<<"\t\t************************************************"<<endl;
 if(strlen(mimaStr)==0)cout<<"\t\t\t\t [1] 創(chuàng)建密碼"<<endl;
 else cout<<"\t\t\t\t  創(chuàng)建密碼"<<endl;      //密碼已經(jīng)存在就不能創(chuàng)建了
 cout<<"\t\t\t\t [2] 驗證密碼"<<endl;
 cout<<"\t\t\t\t [3] 修改密碼"<<endl;
 cout<<"\t\t\t\t [4] 刪除密碼"<<endl;
 cout<<"\t\t\t\t [5] 退出系統(tǒng)"<<endl;
 cout<<"\t\t************************************************"<<endl;
 xuanze();
}
 
void xuanze()
{
 cout<<"\t\t請輸入你要進(jìn)行的操作數(shù): ";
 char ch;
L: ch=getch();
 if ((ch=='1' && strlen(mimaStr)==0) || ch=='2' || ch=='3' || ch=='4' || ch=='5')
 {
 switch(ch)
 {
 case '1':Create_mima();
 break;
 case '2':YanZheng_mima();
 break;
 case '3':Chang_mima();
 break;
 case '4':delete_mima();
 break;
 case '5':exit(0);
 break;
 }
 }
 else goto L;
}
 
int read_file() //讀取密碼文件
{
L: ifstream infile("MiMa_record.txt");
 if (!infile)
 {
 write_file();
 goto L;
 } 
 else
 infile>>mimaStr;
 return 1;
}
 
void write_file()//寫入密碼文件
{
 ofstream outfile("MiMa_record.txt");
 if (!outfile)
 {
 cout<<"can not open the file!"<<endl;
 return;
 } 
 else
 outfile<<mimaStr;
}
 
void jiami_suanfa(char* str) //加密解密算法
{
 int len=strlen(str);
 for (int i=0;i<len;i++)
 str[i]=str[i]^'g';
}
 
void Create_mima() //創(chuàng)建密碼
{
 system("cls");
 char ch;
 int i=0;
 char str[100]; //確認(rèn)密碼存放處
 cout<<"請輸入新建密碼,按Enter結(jié)束(大于等于6位數(shù)): ";
 ch=getch();
 while (i<100)
 {
 if (ch==13 && i>5)break;
 else if(ch==13)ch=getch();
 else
 {
 cout<<"*";
 mimaStr[i++]=ch;
 ch=getch();
 }
 }
 mimaStr[i]='\0';  //結(jié)束標(biāo)志
 i=0;
 cout<<endl<<"請輸入確認(rèn)密碼,按Enter結(jié)束(大于等于6位數(shù)): ";  //第二次輸入密碼
 ch=getch();
 while (i<100)
 {
 if (ch=='\r' && i>5)break;
 else if(ch=='\r')ch=getch();
 else
 {
 cout<<"*";
 str[i++]=ch;
 ch=getch();
 }
 }
 str[i]='\0';  //結(jié)束標(biāo)志
 if (strcmp(mimaStr,str)==0)
 {
 jiami_suanfa(mimaStr);
 write_file();
 cout<<endl<<"創(chuàng)建密碼成功!,任意鍵返回..."<<endl;
 ch=getch();
 display();
 } 
 else
 {
 cout<<"兩次輸入密碼不一樣,創(chuàng)建失敗! 繼續(xù)創(chuàng)建密碼按Enter,任意鍵返回..."<<endl;
 ch=getch();
 if (ch=='\r')Create_mima();
 else display();
 }
}
void YanZheng_mima() //驗證密碼
{
 read_file();
 system("cls");
 char ch;
 char str[100];
 int i=0;
 cout<<"請輸入你要驗證的密碼,Enter結(jié)束: ";
 ch=getch();
 while (i<100)
 {
 if (ch=='\r' && i>5)break;
 else if(ch=='\r')ch=getch();
 else
 {
 cout<<"*";
 str[i++]=ch;
 ch=getch();
 }
 }
 str[i]=0;
 cout<<endl;
 jiami_suanfa(mimaStr); //解密
 if (strcmp(str,mimaStr)==0)
 {
 cout<<"恭喜!驗證成功!任意鍵返回..."<<endl;
 ch=getch();
 display();
 } 
 else
 {
 cout<<"驗證不成功!按Enter繼續(xù)驗證,任意鍵返回..."<<endl;
 ch=getch();
 if (ch=='\r')YanZheng_mima();
 else display();
 }
}
 
void Chang_mima() //修改密碼
{
 read_file();
 system("cls");
 char ch;
 char str[100];
 int i=0;
 cout<<"請輸入原來的密碼,Enter結(jié)束: ";
 ch=getch();
 while (i<100)
 {
 if (ch=='\r' && i>5)break;
 else if(ch=='\r')ch=getch();
 else
 {
 cout<<"*";
 str[i++]=ch;
 ch=getch();
 }
 }
 str[i]='\0';
 cout<<endl;
 i=0;
 jiami_suanfa(mimaStr); //解密
 if (strcmp(str,mimaStr)==0)
 {
 cout<<endl<<"請輸入修改密碼,按Enter結(jié)束(大于等于6位數(shù)): ";
 ch=getch();
 while (i<100)
 {
 if (ch=='\r' && i>5)break;
 else if(ch=='\r')ch=getch();
 else
 {
 cout<<"*";
 mimaStr[i++]=ch;
 ch=getch();
 }
 }
 mimaStr[i]='\0';  //結(jié)束標(biāo)志
 i=0;
 cout<<endl<<"請輸入確認(rèn)密碼,按Enter結(jié)束(大于等于6位數(shù)): ";  //第二次輸入密碼
 ch=getch();
 while (i<100)
 {
 if (ch=='\r' && i>5)break;
 else if(ch=='\r')ch=getch();
 else
 {
 cout<<"*";
 str[i++]=ch;
 ch=getch();
 }
 }
 str[i]='\0';  //結(jié)束標(biāo)志
 if (strcmp(mimaStr,str)==0)
 {
 jiami_suanfa(mimaStr);
 write_file();
 cout<<endl<<"修改密碼成功!,任意鍵返回..."<<endl;
 ch=getch();
 display();
 } 
 else
 {
 cout<<endl<<"兩次輸入密碼不一樣,修改失敗! 繼續(xù)修改密碼按Enter,任意鍵返回..."<<endl;
 ch=getch();
 if (ch=='\r')Chang_mima();
 else display();
 }
 } 
 else
 {
 cout<<endl<<"輸入密碼不匹配!你不能修改該密碼!任意鍵返回..."<<endl;
 ch=getch();
 display();
 }
}
 
void delete_mima() //刪除密碼
{
 read_file();
 system("cls");
 char ch;
 char str[100];
 int i=0;
 cout<<"請輸入原來的密碼,Enter結(jié)束: ";
 ch=getch();
 while (i<100)
 {
 if (ch=='\r' && i>5)break;
 else if(ch=='\r')ch=getch();
 else
 {
 cout<<"*";
 str[i++]=ch;
 ch=getch();
 }
 }
 str[i]='\0';
 cout<<endl;
 i=0;
 jiami_suanfa(mimaStr); //解密
 if (strcmp(str,mimaStr)==0)
 {
 cout<<"確定刪除請按'y'or'Y',任意鍵取消返回..."<<endl;
 ch=getch();
 if (ch=='y' || ch=='Y')
 {
 mimaStr[0]='\0';
 write_file();
 cout<<"刪除成功,任意鍵返回..."<<endl;
 ch=getch();
 display();
 }
 else display();
 }
 else
 {
 cout<<endl<<"輸入密碼不匹配!你不能刪除該密碼!任意鍵返回..."<<endl;
 ch=getch();
 display();
 }
}
 
//mian函數(shù)
void main()
{
 display();
}

關(guān)于利用C++怎么編寫一個密碼管理系統(tǒng)問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI