快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

c语言编写用户注册函数 c语言注册用户名和密码

编一个注册登陆的程序 C语言的

#include stdlib.h

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名申请雅安服务器托管、营销软件、网站建设、永康网站维护、网站推广。

#include stdio.h

#include string.h

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

FILE *fp;

char tid[10], tpass[10];

fp = fopen("c:\\data", "r");

while (!feof(fp)) {

fscanf(fp, "%s%s", tid, tpass);

if (strcmp(tid, id)==0 strcmp(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[]) {

FILE *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 (strcmp(pass, tpass) != 0)

printf("The passwords you pressed are not the same!\n");

else

break;

}

_add(id, pass);

printf("-----------------------Register successfully!\n");

}

void init() {

FILE *fp;

if ((fp=fopen("c:\\data", "r")) == NULL) { // 注意,一定要有个名叫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;

}

搞定了。。。我是用成功了的。。。如果有问题就发信给我。。。。

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

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

#includeiostream

#includefstream// 文件输入输出流

#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;

fintemp;

if(temp[0]==0) return false;

else

return true;

}

void changepass()

{

char pass[PASSLEN];

ofstream fout(infile);

cout"Please Set New Password:";

cinpass;

for(int i=0;iPASSLEN;i++)

if(pass[i]!=0)

foutpass[i]+PASSendl;

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:";

cininput; //从键盘和文件分别读入密码

int len=strlen(input);

//coutlen;system("pause");

for(int i=0;ilen;i++) //这个循环用来判断密码是否吻合

{

int pass;

finpass;

pass-=PASS;

if(input[i]!=char(pass)) //一旦不相同就将 isok 设置为 false 同时推出循环

{

couti" "pass;system("pause");

isok=false;

break;

}

}

if(isok) //如果密码吻合

{

cout"PASS CHECK CORRECT !"endl;

int n;

cout"1 FOR CHANGE PASS OTHER NUMBER FOR CONTIUNE:";

cinn;

if(n==1)

changepass();

//这是接下来你要加的代码了

}

system("pause");

return 0;

}

C语言 编写一个注册函数 要求账号10位字符 密码6位字符 账号密码同时满足条件显示注册成功

#include stdio.h

#include string.h

const char *const ACCT[]="1234567890"

const char *const PSWD[]="123456";

int main()

{

char acct_no[11];

char passwd[7];

gets(acct_no);

gets(passwd);

if ( strcmp(acct_no,ACCT) || strcmp(passwd,PSWD) )

{

printf("账户或密码错误!\n");

return -1;

}

printf("注册成功!\n");

return 0;

}

C语言中的注册表操作函数有哪些?

要调用Windows

API的RegOpenKeyEx(),

RegSetValueEx(),

RegSetValueEx()等函数。首先要确认你的C编译器支持调用Windows

API.

举例:

要自动运行"D:\Myprog\MyProgram.exe",

修改注册表,在

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

中加一项:

RunMyProg="D:\Myprog\MyProgram.exe"

#include

windows.h

static

char

subkey[]

=

"Software\\Microsoft\\Windows\\CurrentVersion\\Run";

static

char

vname[]

=

"RunMyProg";

static

char

exefile[]

=

"D:\\Myprog\\MyProgram.exe";

ULONG

dType

=

REG_SZ,

len

=

0;

HKEY

hKey;

RegOpenKeyEx(HKEY_LOCAL_MACHINE,subkey,0,KEY_SET_VALUE|KEY_QUERY_VALUE,hKey);//打开。

if

(RegQueryValueEx(hKey,

vname,

0,

dType,

NULL,

len))

{

//如果没有RunMyProg,

RegSetValueEx(hKey,

vname,

0,

REG_SZ,

exefile,

strlen(exefile)+1);

//就加上。

}

RegCloseKey(hKey);

//关闭。


分享名称:c语言编写用户注册函数 c语言注册用户名和密码
网站URL:http://6mz.cn/article/doghjod.html

其他资讯