C语言中怎么编写一个让用户注册登陆并将其注册的信息密码保存的程序模块?

就是下次打开这个C程序也能用这个登陆的 程序?具体用到哪些代码请教下,我是小白。
采纳再加分。。 谢谢了

我有一个C++的运行程序需要输入密码的程序,输入正确可以修改密码,密码保存在文件中是加密的。至于注册之类的可以再加上一个文件保存用户名和密码,再在程序里加上功能选择的代码,注册时扫描一遍文件中的名字,如果存在就提示,否则就OK。。。。

#include<iostream>
#include<fstream>// 文件输入输出流
#define PASSLEN 16
#define PASS 3123 //这个东西用来加密密码s
#define infile "XMAN.txt" //保存密码的文件s
using namespace std;
bool exist() //判断密码文件是否存在 不存在表示未设置过密码
{
ifstream fin(infile); //文件输入输出流定义 ifstream +流的名字 用于从文件中读入数据
char temp[PASSLEN];
temp[0]=0;
fin>>temp;
if(temp[0]==0) return false;
else
return true;
}
void changepass()
{
char pass[PASSLEN];
ofstream fout(infile);
cout<<"Please Set New Password:";
cin>>pass;
for(int i=0;i<PASSLEN;i++)
if(pass[i]!=0)
fout<<pass[i]+PASS<<endl;
cout<<"Pass Set Successfully !"<<endl;
}
int main()
{
char input[PASSLEN];
bool isok=true; //判断密码是否吻合
memset(input,0,sizeof(input));
if(!exist()) //密码文件不存在就重新设置密码
{changepass();return 0;}
ifstream fin(infile);
cout<<"Please Input The Password:";
cin>>input; //从键盘和文件分别读入密码
int len=strlen(input);
//cout<<len;system("pause");
for(int i=0;i<len;i++) //这个循环用来判断密码是否吻合
{
int pass;
fin>>pass;
pass-=PASS;
if(input[i]!=char(pass)) //一旦不相同就将 isok 设置为 false 同时推出循环
{
cout<<i<<" "<<pass;system("pause");
isok=false;
break;
}
}
if(isok) //如果密码吻合
{
cout<<"PASS CHECK CORRECT !"<<endl;
int n;
cout<<"1 FOR CHANGE PASS OTHER NUMBER FOR CONTIUNE:";
cin>>n;
if(n==1)
changepass();
//这是接下来你要加的代码了
}
system("pause");
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-07-19
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

bool search(char id[], char pass[]) {

*fp;
char tid[10], tpass[10];
fp = fopen("c:\\data", "r");
while (!feof(fp)) {
fscanf(fp, "%s%s", tid, tpass);
if (
(tid, id)==0 &&
(tpass, pass)==0) {
fclose(fp);
return true;
}
}
fclose(fp);
return false;
}

bool login() {
char id[10], pass[10];
printf("Login\nPress the id: ");
scanf("%s", id);
printf("Press the password: ");
// 可以自行将password处理成*号, 如果不会可以发信给我
scanf("%s", pass);
printf("-----------------------");
if (search(id, pass))
return true;
else
return false;
}

void _add(char id[], char pass[]) {

*fp;
fp=fopen("c:\\data", "a");
// 在写入文件时可以按一定的排序方式插入,可减少以后Login时的search时间
fprintf(fp, "%s %s\n", id, pass);
fclose(fp);
}

void regis() {
char id[10], pass[10], tpass[10];
printf("Register\nPress the id: ");
scanf("%s", id);
while (true) {
printf("Press the password: ");
scanf("%s", pass);
printf("Press the password again: ");
scanf("%s", tpass);
if (
(pass, tpass) != 0)
printf("The passwords you pressed are not the same!\n");
else
break;
}
_add(id, pass);
printf("-----------------------Register successfully!\n");
}

void init() {

*fp;
if ((fp=fopen("c:\\data", "r")) ==
) { // 注意,一定要有个名叫data(没有
)的合法文件在C盘

printf("---------File is not exist\n");
system("pause");
exit(0);
}
else
fclose(fp);
}

int main(void){
int command;
init(); // 检查data文件在不在
while (true) {
printf("-----------------------(Login: 1 Register: 2 Exit: 3)\n");
scanf("%d", &command);
printf("-----------------------\n");
// 这里可以编写command的检测语句
if (command == 3)
break;
else if (command == 1) {
if (!login())
printf("ID is not exist or password is wrong!\n");
else
printf("Login successfully!\n");
}
else
regis();
}
return 0;
}
第2个回答  2015-09-02
#include "stdafx.h"
#include "string.h"
#define n 20

void zhuce();
void denglu();
char yhm[n],mm[n];
int main(int argc, char* argv[])
{
int i;

printf("-----------\n1.注册\n2.登陆\n3.继续\n0.退出\n");
scanf("%d",&i);
switch(i)
{case 0: break;
case 1 : zhuce();break;
case 2: denglu();break;

}

return 0;
}
void zhuce( )
{char temp1[n],temp2[n],temp3[n],yhmtmp[n];

printf("输入用户名\n");
fflush(stdin);//清空缓存
gets(yhmtmp);

printf("输入密码\n");
fflush(stdin);
gets(temp1);
printf("输入密码确认\n");
fflush(stdin);
gets(temp2);
if(!strcmp(temp1,temp2))
{strcpy(mm,temp1);
printf("注册成功\n");

}
else
{printf("输入密码确认\n");
gets(temp3);
if(!strcmp(temp1,temp3))
{strcpy(mm,temp1);
printf("注册成功\n");

}
else

printf("注册失败\n");

}

}
void denglu( )
{
char s1[n],s2[n];
printf("输入用户名\n");
fflush(stdin);
gets(s1);
printf("输入密码\n");
fflush(stdin);
gets(s2);
if((strcmp(s1,yhm))&&(strcmp(s2,mm)))
printf("登陆成功\n");

}本回答被网友采纳
第3个回答  2011-12-21
额,c要保存信息可以简单的保存到文件中,用文件的打开读写操作,open read write等函数,然后指定运行程序的时候读取指定文件,解析出来用户注册的密码....简单的大概是这样
有疑问请追问追问

不懂阿,就是有没有资料啥的,还有最好有代码阿~~

追答

额,是在不好意思,U盘中太乱了,实在找不到,你可以在网上找找文件读写的例子,很简单,几个函数而已...

第4个回答  推荐于2017-11-24
//自己早上看到你这个问题专门为你写的 趁热看看
Registered and Login system

1 UserReg
2 Login
3 Exit
1
Registered Account:
Please input your name:
ka西瓜
Please input your password:
123456
Registered Success!

Registered and Login system

1 UserReg
2 Login
3 Exit
2
Login Account:
Please input Username:
ka西瓜
Please input Password:
123456
OK!Login Success!
Welcome back,ka西瓜!
Press any key to continue
#include <stdio.h>
#include <windows.h>

void UserReg(); //用户注册函数
void Login(); //用户登录函数
main()
{
int selectNum;
printf("\nRegistered and Login system\n\n");
printf("1 UserReg\n");
printf("2 Login\n");
printf("3 Exit\n");
scanf("%d",&selectNum);
switch (selectNum)
{
case 1:UserReg();
break;
case 2:Login();
break;
case 3:printf("Exit Program!\n");
exit(1);
break;
}
}

void UserReg()
{
FILE *fp;
char Linedata[50]={0},User[20],Pass[20];
fp = fopen("data.dat","at");
printf("Registered Account:\n");
printf("Please input your name:\n");
fflush(stdin);
gets(User);
printf("Please input your password:\n");
fflush(stdin);
gets(Pass);
strcpy(Linedata,User);
strcat(Linedata,",");
strcat(Linedata,Pass);
strcat(Linedata,"\n");
fputs(Linedata,fp);
fclose(fp);
printf("Registered Success!\n");
main();
}

void Login()
{
FILE *fp;
int find=0;
char User[20],Pass[20],Userstrcat[50]={0};
char Userdata[50]={0};
fp = fopen("data.dat","r");
printf("Login Account:\n");
printf("Please input Username:\n");
fflush(stdin);
gets(User);
printf("Please input Password:\n");
fflush(stdin);
gets(Pass);
strcpy(Userstrcat,User);
strcat(Userstrcat,",");
strcat(Userstrcat,Pass);
strcat(Userstrcat,"\n");
while (!feof(fp))
{
fgets(Userdata,19,fp);
if (strcmp(Userdata,Userstrcat)==0 )
{
printf("OK!Login Success!\n");
printf("Welcome back,%s!\n",User);
find=1;
break;
}
}
if (!find)
{
printf("Username or Password incorrect!\n");
}
fclose(fp);
}追问

你好,请问你看看我在编译运行一遍之后为什么运行第二遍会出现如图报错???还有,这个是怎么编写的啊,能教教我么呵呵

追答

根据错误提示 貌似是权限问题

你这个是什么编译器?

我的是VC6写的

怎么编写? 我都写在上面啊

可以教你啊

追问

enen QQ472157527

追答

1227812201

本回答被提问者采纳
相似回答