密码验证程序用C++编的

要求:有创建密码,验证密码和修改密码三个功能,输入密码时候用“*”掩盖,创建的密码用记事本存起来,但是不是原原本本存进去,是加一个运算,把密码转换成另外一个字符串存进去然... 要求:有创建密码,验证密码和修改密码三个功能,输入密码时候用“*”掩盖,创建的密码用记事本存起来,但是不是原原本本存进去,是加一个运算,把密码转换成另外一个字符串 存进去 然后要验证的时候再反方向弄出来 与输入的密码相比较 密码只能创建一次,创建之后就只能修改密码 和验证密码,修改密码的时候要求两次输入原来的密码 对的上号才能修改。 急着用,各位大哥能漂漂亮亮得帮我解决这个问题的话 我的积分全给他都没问题 但无论如何我会再追加50分的积分!! 感谢各位啦!
只要求是控制台的程序,VC6.0能编译通过。再次拜谢各位啦!!
分数不是问题
展开
 我来答
口天无才
推荐于2016-12-01 · TA获得超过429个赞
知道小有建树答主
回答量:153
采纳率:0%
帮助的人:225万
展开全部
200分,如果你在的话,我三个小时不用就可以帮你搞掂...........

呵呵,还不用三个小时呢!!!!!!!

搞掂啦!!

除了你要求的功能之外,我还增加了删除密码的这个功能,目的就是要让你方便测试

还要,你不要看程序表面没有什么检错报错的功能,主要的原因已经将一切有可能输入错误的地方给隔离开了,不信你试试看,也就应了那句话你想输入错误也不行啊,如果我还有时间,我在改一改那个加密的算法....

现在就把源程序贴出来..........
编译环境是vc6.0 系统环境是winxp

如果不是在这个环境下面编译的话我很难保证没有什么错误出现...

///////////////////////////////////////////////////////////

#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欢迎使密码验证系统"<<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();
}
铜锣湾的小野猪
2008-06-30
知道答主
回答量:11
采纳率:0%
帮助的人:0
展开全部
提个建议啊!(一楼别抽我=.=)
else goto L;
goto会破坏程序结构,应该改用指针.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友10e35b164
2008-06-29
知道答主
回答量:10
采纳率:0%
帮助的人:0
展开全部
楼上的hucice 好厉害 赞
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式