对您有一点点用,或者喜欢,点点赞,点点关注可以吗,谢谢!
功能介绍:1.怎么创建密码,输入两次
2.怎么修改密码
3.怎么删除密码
目录
2. 功能代码
1.
2.
是不是有点意思,那还不ctrl-c ctrl-v 弄入你的IDE环境下,试下
-
// mima.cpp: 主项目文件。
-
-
#include "stdafx.h"
-
-
///
-
-
#include <iostream>
-
#include <conio.h>
-
#include <string.h>
-
#include <fstream>
-
//#include <windows.h>
-
using
namespace
std;
-
void display();
//主界面函数
-
void xuanze();
//选择函数
-
-
int read_file();
//读取密码文件
-
void write_file();
//写入密码文件
-
void Create_mima();
//创建密码
-
void YanZheng_mima();
//验证密码
-
void Chang_mima();
//修改密码
-
void delete_mima();
//删除密码
-
//
-
-
void jiami_suanfa(char* str);
//加密解密算法
-
-
char mimaStr[
100];
//全局变量
-
//以上是函数的声明部分
-
-
//下面是函数的实现部分
-
-
void display() //主界面函数
-
{
-
system(
"cls");
-
read_file();
-
cout<<
"\t\t************************************************"<<
endl;
-
cout<<
"\t\t\t\t欢迎使console密码系统"<<
endl;
-
cout<<
"\t\t************************************************"<<
endl;
-
if(
strlen(mimaStr)==
0)
cout<<
"\t\t\t\t [1] 创建密码"<<
endl;
-
else
cout<<
"\t\t\t\t 创建密码"<<
endl;
//密码已经存在就不能创建了
-
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] 退出系统"<<
endl;
-
cout<<
"\t\t************************************************"<<
endl;
-
xuanze();
-
}
-
-
void xuanze()
-
{
-
cout<<
"\t\t请输入你要进行的操作数: ";
-
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() //创建密码
-
{
-
system(
"cls");
-
char ch;
-
int i=
0;
-
char str[
100];
//确认密码存放处
-
cout<<
"请输入新建密码,按Enter结束(大于等于6位数): ";
-
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';
//结束标志
-
i=
0;
-
cout<<
endl<<
"请输入确认密码,按Enter结束(大于等于6位数): ";
//第二次输入密码
-
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';
//结束标志
-
if (
strcmp(mimaStr,str)==
0)
-
{
-
jiami_suanfa(mimaStr);
-
write_file();
-
cout<<
endl<<
"创建密码成功!,任意键返回..."<<
endl;
-
ch=getch();
-
display();
-
}
-
else
-
{
-
cout<<
"两次输入密码不一样,创建失败! 继续创建密码按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结束: ";
-
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继续验证,任意键返回..."<<
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结束: ";
-
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结束(大于等于6位数): ";
-
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';
//结束标志
-
i=
0;
-
cout<<
endl<<
"请输入确认密码,按Enter结束(大于等于6位数): ";
//第二次输入密码
-
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';
//结束标志
-
if (
strcmp(mimaStr,str)==
0)
-
{
-
jiami_suanfa(mimaStr);
-
write_file();
-
cout<<
endl<<
"修改密码成功!,任意键返回..."<<
endl;
-
ch=getch();
-
display();
-
}
-
else
-
{
-
cout<<
endl<<
"两次输入密码不一样,修改失败! 继续修改密码按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结束: ";
-
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函数
-
void main()
-
{
-
display();
-
}
是不是和给出的效果一致呢, 以上的密码只是简单的异或操作加密,你可以在这基础上加入你的专业级的加密算法试试哈, 什么 des aes都可以哈!
记得点赞和关注哟!
转载:https://blog.csdn.net/kaizi318/article/details/109560184
查看评论