C++控制臺(tái)實(shí)現(xiàn)密碼管理系統(tǒng)
本文實(shí)例為大家分享了C++控制臺(tái)實(shí)現(xiàn)密碼管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
功能介紹:
1.怎么創(chuàng)建密碼,輸入兩次
2.怎么修改密碼
3.怎么刪除密碼
目錄
1.主界面

2. 功能代碼



是不是有點(diǎn)意思,那還不ctrl-c ctrl-v 弄入你的IDE環(huán)境下,試下
// mima.cpp: 主項(xiàng)目文件。
#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();//寫(xiě)入密碼文件
void Create_mima(); //創(chuàng)建密碼
void YanZheng_mima(); //驗(yàn)證密碼
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] 驗(yàn)證密碼"<<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請(qǐng)輸入你要進(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()//寫(xiě)入密碼文件
{
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<<"請(qǐng)輸入新建密碼,按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<<"請(qǐng)輸入確認(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() //驗(yàn)證密碼
{
read_file();
system("cls");
char ch;
char str[100];
int i=0;
cout<<"請(qǐng)輸入你要驗(yàn)證的密碼,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<<"恭喜!驗(yàn)證成功!任意鍵返回..."<<endl;
ch=getch();
display();
}
else
{
cout<<"驗(yàn)證不成功!按Enter繼續(xù)驗(yàn)證,任意鍵返回..."<<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<<"請(qǐng)輸入原來(lái)的密碼,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<<"請(qǐng)輸入修改密碼,按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<<"請(qǐng)輸入確認(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<<"請(qǐng)輸入原來(lái)的密碼,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<<"確定刪除請(qǐng)按'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();
}
是不是和給出的效果一致呢, 以上的密碼只是簡(jiǎn)單的異或操作加密,你可以在這基礎(chǔ)上加入你的專業(yè)級(jí)的加密算法試試哈, 什么 des aes都可以哈!
關(guān)于管理系統(tǒng)的更多內(nèi)容請(qǐng)點(diǎn)擊《管理系統(tǒng)專題》進(jìn)行學(xué)習(xí)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C++實(shí)現(xiàn)簡(jiǎn)單的圖書(shū)管理系統(tǒng)
- C++實(shí)現(xiàn)簡(jiǎn)單職工信息管理系統(tǒng)
- C++實(shí)現(xiàn)簡(jiǎn)單的學(xué)生管理系統(tǒng)
- C++學(xué)生信息管理系統(tǒng)
- C++實(shí)現(xiàn)停車(chē)場(chǎng)管理系統(tǒng)
- C++實(shí)現(xiàn)簡(jiǎn)單的信息管理系統(tǒng)
- C++實(shí)現(xiàn)企業(yè)職工工資管理系統(tǒng)
- C++實(shí)現(xiàn)簡(jiǎn)單職工管理系統(tǒng)
- C++基礎(chǔ)學(xué)生管理系統(tǒng)
- C++實(shí)現(xiàn)景區(qū)信息管理系統(tǒng)
相關(guān)文章
C++中的opeartor?new和placement?new使用步驟
這篇文章主要介紹了C++中的opeartor?new和placement?new詳解,在很多情況下,placement?new的使用方法和其他普通的new有所不同。這里提供了它的使用步驟,需要的朋友可以參考下2022-10-10
C語(yǔ)言中二級(jí)指針的應(yīng)用小結(jié)
二級(jí)指針是C語(yǔ)言中指向指針的指針,常用于在函數(shù)中修改指針的地址,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-11-11
C++設(shè)計(jì)模式之建造者模式(Builder)
這篇文章主要介紹了C++設(shè)計(jì)模式之建造者模式Builder的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03
帶頭結(jié)點(diǎn)的鏈表的基本操作(超詳細(xì))
鏈表是一種動(dòng)態(tài)分配空間的存儲(chǔ)結(jié)構(gòu),能更有效地利用存儲(chǔ)空間,通過(guò)對(duì)單鏈表基本操作的代碼實(shí)現(xiàn),我深刻領(lǐng)悟到以“指針”指示元素的后繼,在插入或刪除元素時(shí)不需要移動(dòng)元素2023-07-07
C++實(shí)現(xiàn)班車(chē)管理系統(tǒng)課程設(shè)計(jì)
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)班車(chē)管理系統(tǒng)課程設(shè)計(jì),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單猜拳小游戲
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單猜拳小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-03-03
OpenCV圖像分割中的分水嶺算法原理與應(yīng)用詳解
這篇文章主要為大家詳細(xì)介紹了OpenCV圖像分割中的分水嶺算法原理與應(yīng)用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01
C++獲取字符串長(zhǎng)度的幾個(gè)函數(shù)方式
這篇文章主要介紹了C++獲取字符串長(zhǎng)度的幾個(gè)函數(shù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-12-12

