當前位置:首頁 » 編程語言 » c語言程序登錄系統的代碼
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言程序登錄系統的代碼

發布時間: 2023-08-10 21:45:23

c語言編程實現用戶的注冊和登錄 求代碼啊

模擬用戶注冊和登陸可以用文件來保存用戶名和密碼。注冊就是向文件里寫,用if判斷兩次密碼是否一致。連續三次,可以有一個變數,每次輸入加一,變數大於三就提示登陸不成功。用戶名不對,那你就把你輸入的用戶名和文件里的用戶名是否一致。

Ⅱ 編一個注冊登陸的程序 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語言設計一個用戶登錄軟體,求源代碼

void student::print()
{
char s[10];
int i=0;
string password="guest";
cout<<endl<<endl<<endl;
cout<<"\t\t**************************************\n";
cout<<"\t\t***** 學生信息管理系統 *****\n";
cout<<"\t\t**************************************\n";
cout<<"\t\t請輸入密碼(7位數):";
s[0]=getch();
while(s[i]!='\r') //輸入回車鍵停止
{
cout<<"*";
s[++i]=getch();
}
s[i]='\0';
cout<<endl;
if(s==password)
cout<<"\t\t歡迎使用學生信息管理系統!\n";
else
{
cout<<"\t\t您輸入的密碼有誤!無權使用\n";
exit(0);
}
system("cls");
}