帳號c語言,c語言用戶登錄代碼

本文目錄一覽:

c語言 銀行賬戶信息管理系統

#include conio.h

#include string.h

#include stdio.h

#include stdlib.h

char cFile[] = “date.txt”;

struct bank

{

char id[10+1];

char psw[6+1];

double money;

};

welcome1()

{

printf(“\n\n\t\t歡迎使用虛擬銀行自動取款機服務!\t\t\n\n”);

printf(“請選擇功能:\n”);

printf(“\n=================================================\n”);

printf(” || 請輸入序號 ||\n”);

printf(” || 1.新用戶開戶。 ||\n”);

printf(” || 2.老用戶登陸。 ||\n”);

printf(” || 3.退出系統。 ||\n”);

printf(“=================================================\n”);

}

welcome2()

{

printf(“\n\n\t\t註冊須知\n\n”);

printf(“**************************************************\n”);

printf(“* 1.請填寫您的真實資料! *\n”);

printf(“* 2.開戶首期必須存入100元以上 *\n”);

printf(“**************************************************\n”);

}

welcome3()

{

printf(“\n\n\t\t\3 歡迎進入虛擬銀行系統 \3\n\n”);

printf(“\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n”);

printf(“\1\1\t 請選擇功能:1.取款(最多透資2000); \1\1\n”);

printf(“\1\1\t 2.存款; \1\1\n”);

printf(“\1\1\t 3.查詢餘額; \1\1\n”);

printf(“\1\1\t 4.修改密碼; \1\1\n”);

printf(“\1\1\t 5.返回主頁面; \1\1\n”);

printf(“\1\1\t 任意鍵退出. \1\1\n”);

printf(“\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n”);

}

int search(char* user, char* pwd, char* real_pwd)/*判斷帳號是否相同,不相同返回1*/

{

FILE* file;

char user_buff[256], pwd_buff[256];

file = fopen(cFile, “r”);

if (!file) return 0;

while (!feof(file))

{

if (fscanf(file, “%s%s\n”, user_buff, pwd_buff) == EOF) return 0;

if (!strcmp(user_buff, user))

{

if (real_pwd) strcpy(real_pwd, pwd_buff);

return 1;

}

}

fclose(file);

return 0;

}

int add(char* user, char* pwd, double coin_n)

{

FILE* file;

file = fopen(cFile, “a”);

if (!file) return 0;

fprintf(file, “%s %s %.2lf\n”, user, pwd, coin_n);

fclose(file);

return 0;

}

int wenjian(char* user, char* pwd,double coin)

{

if (search(user, pwd, NULL)) return 0;

else add(user, pwd, coin);

return 1;

}

zhuce()/*註冊*/

{

struct bank *p;

int i=0,k=0,judge1,judge2;

char name[30];

char sex,ch;

char sh[18];

int n;

p=(struct bank*)malloc(sizeof(struct bank));/*給p分配內存*/

welcome2();

printf(“請輸入您的名字(純英文):”);

gets(name);

printf(“請輸入您的性別(男:1 女2):”);

fflush(stdin);

scanf(“%c”,sex);

fflush(stdin);

printf(“請輸入您的身份證號碼:”);

gets(sh);

for(n=0;nstrlen(name);n++)/*判斷輸入信息是否正確*/

{

if(name[n]=’0’name[n]=’9′)

{

printf(“您輸入的名字有誤!\n”);

printf(“\n請選擇:按1返回主頁面. 按任意鍵退出:”);

fflush(stdin);

scanf(“%c”,ch);

fflush(stdin);

if(ch==’1′){system(“cls”);main();}

else exit(0);

}

}

if(sex!=’1’sex!=’2′)/*判斷輸入信息是否正確*/

{

printf(“您輸入的性別不對!\n”);

printf(“\n請選擇:按1返回主頁面. 按任意鍵退出:”);

fflush(stdin);

scanf(“%c”,ch);

fflush(stdin);

if(ch==’1′){system(“cls”);main();}

else exit(0);

}

if(strlen(sh)!=18)/*判斷輸入信息是否正確*/

{

printf(“您輸入的身份證號碼不全!\n”);

printf(“\n請選擇:按1返回主頁面. 按任意鍵退出:”);

fflush(stdin);

scanf(“%c”,ch);

fflush(stdin);

if(ch==’1′){system(“cls”);main();}

else exit(0);

}

for(n=0;nstrlen(sh)-1;n++)/*判斷輸入信息是否正確*/

{

if(sh[n]48||sh[n]57)

{

printf(“您輸入的身份證號碼非法!\n”);

printf(“\n請選擇:按1返回主頁面. 按任意鍵退出:”);

fflush(stdin);

scanf(“%c”,ch);

fflush(stdin);

if(ch==’1′){system(“cls”);main();}

else exit(0);

}

else

{

if(sh[18]!=’x’sh[18]48sh[18]57)

{

printf(“您輸入的身份證號碼非法!\n”);

printf(“\n請選擇:按1返回主頁面. 按任意鍵退出:”);

fflush(stdin);

scanf(“%c”,ch);

fflush(stdin);

if(ch==’1′){system(“cls”);main();}

else exit(0);

}

}

}

printf(“請輸入您的帳號(10位純數字):\n”);

fflush(stdin);

scanf(“%s”,p-id);

fflush(stdin);

while(i strlen(p-id))

{

if((p-id[i] 48) || (p-id[i] 57))

{

judge1=0;

}

i++;

}

while(strlen(p-id)!=10 ||judge1==0)/*判斷帳號的正確性*/

{

printf(“您輸入的帳號不正確,必須為10位純數字!”);

printf(“請重新輸入(10位純數字):”);

fflush(stdin);

scanf(“%s”,p-id);

fflush(stdin);

}

printf(“請輸入您的密碼(6位純數字):\n”);

fflush(stdin);

scanf(“%s”,p-psw);

fflush(stdin);

while(k strlen(p-psw))

{

if((p-psw[k] 48) || (p-psw[k] 57))

{

judge2=0;

}

k++;

}

while(strlen(p-psw)!=6 ||judge2==0)/*判斷密碼形式的正確性*/

{

printf(“您輸入不正確!密碼必須為6位純數字!\n”);

printf(“請重新輸入密碼(6位純數字):”);

fflush(stdin);

scanf(“%s”,p-psw);

fflush(stdin);

}

printf(“請輸入您的首期存款:”);

fflush(stdin);

scanf(“%lf”,p-money);

fflush(stdin);

while((p-money)100)

{

printf(“您必須存入100元以上,請重新輸入:”);

fflush(stdin);

scanf(“%lf”,p-money);

fflush(stdin);

}

if (wenjian(p-id,p-psw,p-money))/*存入文件並輸出基本信息*/

{

system(“cls”);

printf(“註冊成功!”);

printf(“您的註冊信息如下,請牢記:\n”);

printf(“名字:”);

puts(name);

printf(“性別代碼:%c\n”,sex);

printf(“身份證號碼:”);

puts(sh);

printf(“帳號:”);

puts(p-id);

printf(“密碼:”);

puts(p-psw);

printf(“您帳戶里的餘額為:%.2lf\n”,p-money);

printf(“請選擇:按1返回主頁面. 按任意鍵退出:”);

fflush(stdin);

scanf(“%c”,ch);

fflush(stdin);

if(ch==’1′){system(“cls”);main();}

else exit(0);

}

else/*如有相同帳號,註冊失敗*/

{

system(“cls”);

printf(“您輸入的帳號已經存在!註冊失敗!\n”);

printf(“請選擇:按1返回主頁面. 按任意鍵退出:”);

scanf(“%c”,ch);

if(ch==’1′){system(“cls”);main();}

else exit(0);

}

}

gongneng(char Account[10+1],char Password[6+1],double Money)/*登陸成功後的功能界面*/

{

FILE *ps;

struct bank xin[1000];

int k=0,b=0;

char mima[6+1],Chiose,x;

char count[10+1],word[6+1];

double inmoney,outmoney,addmoney;

welcome3();

fflush(stdin);

scanf(“%c”,Chiose);

fflush(stdin);

ps=fopen(cFile,”r”);

if (!ps)

{

printf(“不能打開文件!按任意鍵退出!”);

fflush(stdin);

scanf(“%c”,x);

fflush(stdin);

exit(0);

}

if(Chiose==’1′)

{

printf(“輸入您的取款金額:”);

fflush(stdin);

scanf(“%lf”,outmoney);

fflush(stdin);

while(!feof(ps))

{

fscanf(ps, “%s %s %lf”,xin[k].id,xin[k].psw,xin[k].money);

k++;

}

fclose(ps);

ps=fopen(cFile,”wb”);

if (!ps)

{

printf(“不能打開文件!按任意鍵退出!”);

fflush(stdin);

scanf(“%c”,x);

fflush(stdin);

exit(0);

}

while(!feof(ps))

{

//printf(“%s %s %.2lf\n”,xin[b].id,xin[b].psw,xin[b].money);

if ((strcmp(Account, xin[b].id)==0)(strcmp(Password, xin[b].psw)==0))

{

xin[b].money=xin[b].money-outmoney;

}

printf(“%.2lf\n”,xin[b].money);

fprintf(ps, “%s %s %.2lf\n”, xin[b].id, xin[b].psw, xin[b].money);

b++;

}

}

}

denglu()/*登陸*/

{

FILE *fp;

char account[10+ 1],password[6 + 1],h;

int m=0;

char real_account[10+ 1]; /* 帳號緩存 */

char real_password[6 + 1]; /* 密碼緩存*/

double real_money_o=0.0; /*存款緩存*/

printf(“請輸入您的帳號(10位純數字):”);

gets(account);

printf(“請輸入您的密碼(6位純數字):”);

gets(password);

fp = fopen(cFile, “r”);

if (!fp)

{

printf(“不能打開文件!按任意鍵退出!”);

fflush(stdin);

scanf(“%c”,h);

fflush(stdin);

exit(0);

}

while (m=2) /*判斷是否輸入錯3次了*/

{

while(fscanf(fp, “%s %s %lf”, real_account, real_password,real_money_o) != EOF) /*循環判斷帳號密碼*/

{

if ((strcmp(real_account, account)==0)(strcmp(real_password, password)==0))

{

system(“cls”);

printf(“登陸成功!”);

gongneng(real_account,real_password,real_money_o);

fclose(fp);

return 0;

}

}

rewind(fp); /*重新打開文件,進行新一輪的密碼驗證*/

printf(“您輸入的帳號不存在或密碼不正確!\n請重新輸入:\n”);

m++;

printf(“請輸入您的帳號(10位純數字):”);

fflush(stdin);

gets(account);

fflush(stdin);

printf(“請輸入您的密碼(6位純數字):”);

fflush(stdin);

gets(password);

fflush(stdin);

}

fclose(fp);

printf(“您輸入帳號密碼不正確已經3次,您被強制退出系統(按任意鍵退出)!”);

fflush(stdin);

scanf(“%c”,h);

fflush(stdin);

exit(0);

}

int main()

{

char chiose;

welcome1();

scanf(“%c”,chiose);

getchar();

if(chiose =’0′ ||chiose=’4′)

{

while(chiose =’0′ || chiose=’4′)

{

printf(“您的輸入有誤,請重新輸入:”);

scanf(“%c”,chiose);

getchar();

}

}

if(chiose==’1′)

{

system(“cls”);

zhuce();/*註冊*/

}

if(chiose==’2′)

{

system(“cls”);

denglu();/*登陸*/

}

if(chiose==’3′)

{

printf(“謝謝您的使用!”);

exit(0);

}

}

C語言怎樣設置特定的密碼帳號登錄系統?

首先需要確定使用的是那種編譯環境,如turbo C,Unix C還是VC,然後在選用編譯器提供的合適的API函數,這樣才能達到事半功倍的效果,寫出高效率的代碼。不過,不管是基於那種編程環境,基本思路是一樣的,就是通過字符串讀取函數gets()從客戶端(命令窗口或對話框)讀取用戶輸入的用戶名和密碼,然後與設置好的用戶名和密碼分別進行比較(可以採用字符串比較函數strcmp()),比較結果為真,則用戶名和密碼匹配,從登陸界面切換到執行界面,否則,提示錯誤。

用C語言編寫銀行帳戶賬戶管理系統

使用 C 語言編寫一個銀行帳戶管理系統?你的這個編程要求實在是太高了,肯定是不會有人滿足你的要求的。

因為這個要求已經不是簡單地答疑 C 語言的語法錯誤之類的問題了,而是需要從頭設計整個該帳戶管理系統的各種數據存儲結構、以及各種算法(在編寫此軟件的過程中,肯定需要涉及:到底採用哪一種排序算法效率最高、以及採取哪一種查找算法對人員進行查詢效率最高),並且要想徹底從編寫一個源程序,到編譯、鏈接、直到該應用軟件能夠運行出用戶所要求的最終正確結果,那是需要花費很多的時間和精力去調試的,而不是只要寫出程序代碼,即使程序的編程思路是正確的,也不一定能夠保證程序的運行結果是正確的。

C語言用戶登錄系統賬戶密碼比對

#include stdio.h

#include string.h

typedef struct account{

    char name[32];

    char acc[16];

    char psw[16];

}Acc;

//    data是結構體數組,filename是文件絕對地址,n保存讀入的結構體數量 

void GetDataFromTxt(Acc* data, const char* filename, int* n)

{

    FILE *fp = fopen(filename, “r”);

    if( NULL == fp ){

        printf(“Open file failed or no this file!\n”);

        return;

    }

    

    int i = 0;

    while( !feof(fp) )

    {

        fscanf(fp, “%s %s %s”, data[i].name, data[i].acc, data[i].psw);

        i++;        

    }

    *n = i;    

}

int main()

{

    int i, n;

    Acc data[100];

    //    獲取數據 

    GetDataFromTxt(data, “E:\\secret.txt”, n);

    printf(“n = %d\n”, n);

    printf(“姓名    賬號          密碼\n”); 

    for(i = 0; i  n; ++i)

        printf(“%-4s %-16s %-10s\n”, data[i].name, data[i].acc, data[i].psw);

        

    //    登錄示例 

    putchar(‘\n’);

    char acc[16], psw[16];

    do{

        //    這裡只是粗略地寫了一個

        //    具體的賬號錯誤或者密碼錯誤自行發揮 

        printf(“請輸入賬號:”);

        scanf(“%s”, acc);

        printf(“請輸入密碼:”);

        scanf(“%s”, psw);

        for(i = 0; i  n; ++i)

        {

            if( strcmp(acc,data[i].acc)==0  strcmp(psw,data[i].psw)==0 ){

                printf(“登陸成功!\n”);

                break; 

            }

        }

        if( i == n ){

            printf(“賬號或密碼不正確!請重新輸入!\n\n”); 

        }else{

            break;

        }        

    }while(1);

    printf(“Bye bye!!!\n”);     

         

    return 0;

}

C語言用字符串比較函數驗證賬號和密碼?

#include string.h

char user[]=”輸入的帳號”, pwd[]=”輸入的密碼”;

if (strcmp(“真實帳號”, user) == 0 strcmp(“對應密碼”, pwd) == 0) {

printf(“驗證成功!”);

} else {

printf(“帳號或密碼錯誤!”);

}

c語言編寫註冊與登錄的程序

希望對你有所幫助

#includestdio.h

#includestdlib.h

#includestring.h

#includectype.h

#define N 100

struct user

{

int user_id;

char user_name[19];//最大18位

char password[13];//最大13位

char like[255];

char sign[255];

};

/*

* 驗證用戶名長度是否合法

*/

int length_user_name(char *p)

{

int l;

l=strlen(p);

if(l18||l1)

{

return 0;

}

else

return l;

}

/*

* 判斷用戶名是否有效

*/

int valid_user_name(char *p)

{

int i=0;

int len = strlen(p);

if((*p = ‘a’ *p = ‘z’) || (*p = ‘A’ *p =’Z’)) //判斷首字符是不是字母

{

for(i = 0; i len; i++)

{

if(!(p[i] == ‘_’ || (p[i] = ‘a’ p[i] = ‘z’) || (p[i] = ‘A’ p[i] =’Z’)

||(p[i] =’0′ p[i] = ‘9’))) //判斷後面字符是否有效

return 0;

}

return 1;

}

else

return 0;

}

/*

* 判斷用戶名是否有效

*/

int is_username_valid(char *p)

{

if((*p = ‘a’ *p = ‘z’) || (*p = ‘A’ *p =’Z’))

{

p++;

while(*p)

{

if(!(isalpha(*p) || *p == ‘_’ || isdigit(*p)))

return 0;

p++;

}

return 1;

}

else

{

return 0;

}

}

/*

* 密碼長度有效性驗證

*/

int length_password(char *p)

{

int len;

len = strlen(p);

if(len6||len12)

{

return 0;

}

else

return len;

}

/*

* 密碼的有效性驗證

*/

int is_password_valid(char *p)

{

int i=0;

for(;*p != ‘\0’; p++)

{

if(!( (*p = ‘a’ *p = ‘z’) || (*p = ‘A’ *p =’Z’)

||(*p =’0′ *p = ‘9’))) //判斷字符是否有效

return 0;

}

return 1;

}

int two_password_valid(char *p1,char*p2)

{

if(strcmp(p1,p2)==0)

return 1;

else

return 0;

}

/*

* 完成註冊功能

*/

int user_register(struct user *ptr_user,int size)

{

char password[13];

char repassword[13];

if(size==N)

{

puts(“註冊人數以滿!”);

return 0;

}

printf(“請輸入註冊姓名:”);

fflush(stdin);

gets(ptr_user[size].user_name);

if(!(length_user_name(ptr_user[size].user_name)valid_user_name(ptr_user[size].user_name)))

{

printf(“您輸入的姓名無效,用戶名在1-18之間,首字符為字母,後面必須為字母,數字或下劃線!!!”);

return 0;

}

printf(“請輸入註冊密碼:”);

fflush(stdin);

gets(password);

printf(“請再次輸入註冊密碼:”);

fflush(stdin);

gets(repassword);

if(!two_password_valid(password,repassword))

{

printf(“\n兩次輸入的密碼不一致!”);

return 0;

}

else

{

strcpy(ptr_user[size].password,password);

}

if(!(length_password(ptr_user[size].password)is_password_valid(ptr_user[size].password)))

{

printf(“您輸入的密碼無效,密碼應在6-12之間,密碼只能包含字母和數字!!!”);

return 0;

}

printf(“請輸入您的愛好:”);

fflush(stdin);

gets(ptr_user[size].like);

printf(“請輸入您的個性簽名:”);

fflush(stdin);

gets(ptr_user[size].sign);

printf(“您的編號為:%d,這將是您的登陸帳號.”,ptr_user[size].user_id=10000+size);

return 1;

}

/*

* 如果登陸成功則返回第i+1個用戶的信息,否則返回0

*/

int is_my_user(struct user *p,int size)

{

int i;

int zhanghu;

char mima[15];

printf(“請輸入您的帳號: “);

scanf(“%d”,zhanghu);

fflush(stdin);

printf(“請輸入您的密碼: “);

gets(mima);

for(i=0;isize;i++)

{

if((zhanghu == p[i].user_id)(strcmp(mima,p[i].password)==0))

{

return i + 1;

}

}

return 0;

}

void display_user(struct user u)

{

printf(“\n你的帳號是:%d”,u.user_id);

printf(“\n你註冊姓名是:%s”,u.user_name);

printf(“\n你的愛好:%s”,u.like);

printf(“\n你的個性簽名:%s”,u.sign);

}

void update_password(struct user *ptr_user,int size)

{

char mima1[13],mima2[13];

int i = is_my_user(ptr_user,size);

if(i)

{

i–;

}

else

{

printf(“\n帳號密碼不存在!”);

return;

}

printf(“請輸入新密碼: “);

scanf(“%s”,mima1);

printf(“請再次輸入新密碼: “);

scanf(“%s”,mima2);

if(two_password_valid(mima1,mima2) length_password(mima1) is_password_valid(mima1))

{

strcpy(ptr_user[i].password,mima1);//完成新舊密碼的調換

printf(“\n您的的密碼修改成功!”);

}

else

printf(“\您的密碼修改失敗!”);

}

//顯示菜單

int show_menu()

{

int choice;

printf(“\n1.註冊”);

printf(“\n2.登陸”);

printf(“\n3.修改密碼”);

printf(“\n4.退出”);

printf(“\n請選擇1-4\n”);

scanf(“%d”,choice);

return choice;

}

int main()

{

struct user our_users[N];

int count = 0;

int current_user;

while(1)

{

switch(show_menu())

{

case 1:

if(user_register(our_users,count))

{

count++;

printf(“\n註冊成功!”);

}

break;

//註冊

case 2:

if((current_user = is_my_user(our_users,count)))

{

printf(“\n登陸成功!”);

display_user(our_users[current_user – 1]);

}

else

printf(“\n登陸失敗!”);

break;

//登陸

case 3:

update_password(our_users,count);

break;

//修改密碼

case 4:

exit(1);

break;

//退出

default:

printf(“請正確輸入”);

}

}

return 0;

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/306099.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2025-01-02 12:00
下一篇 2025-01-02 12:00

相關推薦

  • Python周杰倫代碼用法介紹

    本文將從多個方面對Python周杰倫代碼進行詳細的闡述。 一、代碼介紹 from urllib.request import urlopen from bs4 import Bea…

    編程 2025-04-29
  • Python字符串寬度不限制怎麼打代碼

    本文將為大家詳細介紹Python字符串寬度不限制時如何打代碼的幾個方面。 一、保持代碼風格的統一 在Python字符串寬度不限制的情況下,我們可以寫出很長很長的一行代碼。但是,為了…

    編程 2025-04-29
  • Python基礎代碼用法介紹

    本文將從多個方面對Python基礎代碼進行解析和詳細闡述,力求讓讀者深刻理解Python基礎代碼。通過本文的學習,相信大家對Python的學習和應用會更加輕鬆和高效。 一、變量和數…

    編程 2025-04-29
  • AES加密解密算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES算法,並對實現過程進…

    編程 2025-04-29
  • 倉庫管理系統代碼設計Python

    這篇文章將詳細探討如何設計一個基於Python的倉庫管理系統。 一、基本需求 在着手設計之前,我們首先需要確定倉庫管理系統的基本需求。 我們可以將需求分為以下幾個方面: 1、庫存管…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演着非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • 寫代碼新手教程

    本文將從語言選擇、學習方法、編碼規範以及常見問題解答等多個方面,為編程新手提供實用、簡明的教程。 一、語言選擇 作為編程新手,選擇一門編程語言是很關鍵的一步。以下是幾個有代表性的編…

    編程 2025-04-29
  • Python實現簡易心形代碼

    在這個文章中,我們將會介紹如何用Python語言編寫一個非常簡單的代碼來生成一個心形圖案。我們將會從安裝Python開始介紹,逐步深入了解如何實現這一任務。 一、安裝Python …

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29

發表回復

登錄後才能評論