當前位置:首頁 » 編程語言 » c語言設計賬號密碼程序
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言設計賬號密碼程序

發布時間: 2022-05-14 18:42:00

A. 如何用c語言編寫密碼程序

1、用一個字元數組來存密碼
再用一個字元數組接收你的輸入,然後用strcmp
來比較,如果返回0則密碼是正確的
2、常式:

#include"stdio.h"
#include"string.h"
intmain()
{
charmima[100]="YuanShi888";
charinput[100]={0};
printf("請輸入密碼:");
gets(input);
if(strcmp(mima,input)==0)
printf("恭喜你,密碼正確! ");
else
printf("對不起,密碼輸入錯誤! ");

}

B. c語言程序設計 密碼設置程序怎麼編寫

#include <stdio.h>
#include <string.h>
#include <conio.h>

int main(int argc,char *argv[])
{
const char user[]="wangpin";/*用戶名自己可改動*/
const char password[]="wangpin@126";/*密碼自己可改動*/
if(argc == 1)
{
printf("Input error! Usage:filename username password\n");
getch();
exit(1);
}
else if(argc == 3)
{
if (strcmp(argv[1],user) != 0 || strcmp(argv[2],password) != 0)
{
printf("Input error: Invalid username or password\n");
getch();
exit(1);
}
}
printf("Authentication Pass..\n");
sound(500);/*最簡單的音樂聲*/
delay(50000);
nosound();
getch();
return 0;
}

先運行這個程序得到一個exe類型的可執行文件,然後可以復制到c盤根目錄下,用桌面左下的圖標進入:開始-程序-附件-命令提示符
然後鍵入 cd \
到c盤根目錄下輸入
exe文件名 wangpin wangpin@126
就是運行這個程序
------------------------------------------------------------------
------------------------------------------------------------------
下面是一個簡單的音樂程序,你可以把它加到上面代替sound()到nosound()那一部分發出<<東方紅>>音樂歌曲(小心!聲音可能很大)
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>

int main(void)
{
int i,j;
int fr[]={392,392,440,294,262,262,220,294,392,392,
440,532,440,392,262,262,220,294,392,294,
262,247,220,196,392,294,330,294,262,262,
220,294,330,294,262,294,262,247,220,196};
int tim[]={4,2,2,8,4,2,2,8,4,4,2,2,2,2,4,2,2,8,4,
4,4,2,2,4,4,4,2,2,4,2,2,2,2,2,2,2,2,2,2,12};
for(i=0;i<40;i++)
{
sound(fr[i]);
delay(tim[i]*100000000);
nosound();
}
system("pause");
return 0;
}

C. c語言賬號與密碼檢查的註解

摘要 編寫一個密碼檢測程序,程序執行時,提示"Input password:「要求用戶輸入密碼(標准密碼預先設定為"hnkd2012」),然後通過字元串比較函數比較輸入密碼和標准密碼是否相等。若相等,則顯示「Congratulation!」;若不相等,則提示"Error,please input again:"重新輸入,3次都不相等則提示"The program is terminated!"並終止程序的執行。要求自己編寫一個字元串比較函數,而不使用系統的strcmp( )函數。

D. 用C語言程序編寫用戶名密碼 程序

#include<stdio.h>
#include<string.h>
void main()
{
int i,flag1,flag2;
char name[20]="lushan",password[10]="123456";
char person[20],password1[10];
for(i=0;i!=3;)
{
printf("Please input the name:\n");
gets(person);
flag1=strcmp(person,name);
printf("Please input the password:\n");
gets(password1);
flag2=strcmp(password,password1);
if(flag1==0&&flag2==0)
{
printf("Pass successfully!");
break;
}
else
{
printf("You have enter the wrong name or password!\n");
i++;
}
}
}

E. c語言設計密碼檢測程序

#include <stdio.h>

#define UC (1U<<1) // upper case
#define LC (1U<<2) // lower case
#define NUM (1U<<3) // 0-9

#define ALL (UC|LC|NUM)

int check(const char pass1[], const char pass2[])
{
const char *p = &pass1[0];
unsigned int flag = 0;

if (strlen(pass1) < 6 || strlen(pass1) > 8)
{
printf("password length is 6 to 8.\n");
return 1;
}

if (strcmp(pass1, pass2))
{
printf("the tow passwords are diffrence.\n");
return 2;
}

while (*p)
{
if (*p >= 'a' && *p <= 'z') flag |= LC;
else if (*p >= 'A' && *p <= 'Z') flag |= UC;
else if (*p >= '0' && *p <= '9') flag |= NUM;
else
{
printf("in valid charactor: %c.\n", *p);
return 3;
}
++p;
}

if (flag == ALL) return 0;

if ((flag & UC) == 0)
{
printf("lack of uppercase.\n");
}

if ((flag & LC) == 0)
{
printf("lack of lowercase.\n");
}

if ((flag & NUM) == 0)
{
printf("lack of number.\n");
}
return -1;
}

int main(int argc, char *argv[])
{
char pass1[100];
char pass2[100];

do {
printf("input password:");
scanf("%s", pass1);
printf("repeat password:");
scanf("%s", pass2);
} while (check(pass1, pass2) != 0);

return 0;
}

F. C語言密碼程序設計

手寫的,沒運行,你自己試一下

#include"stdio.h"
#include"stdlib.h"
#include"string.h"
intmain()
{
char st[6];
printf("輸入登陸密碼: ");
gets(st);
if(strcmp(st,"123")==0)
printf("7");//響鈴
else
printf("Error ");
return(0);
}

G. 怎麼用c語言寫一個創建用戶名和密碼並且能修改密碼的程序

#include <stdio.h>//我自己做的,你拿去用吧!
#include <string.h>
struct e
{
char a[10];
char b[10];
}z;
int main()
{ int t=0;
char s[10],d[10];
FILE *p;
void as();
if ((p=fopen("m.txt","r+"))==NULL)
{
p=fopen("m.txt","w+");
t=1;
}
if(t==1)
{
printf("當前沒有任何用戶\n");
printf("請新建用戶名: ");
scanf("%s",s);
printf("為用戶設置密碼: ");
scanf("%s",d);
strcpy(z.a,s);
strcpy(z.b,d);
fprintf(p,"%s %s",z.a,z.b);
fclose(p);
}
if(t==0)
{
printf("請輸入用戶名: ");
scanf("%s",s);
fscanf(p,"%s %s",z.a,z.b);
fclose(p);
if (!strcmp(z.a,s))
{
printf("請輸入密碼:");
scanf("%s",d);getchar();
if(!strcmp(z.b,d))
{ char i;
printf("是否要修改密碼?(輸入y修改,n退出!)");
scanf("%c",&i);
if(i=='y')
{
printf("請輸入修改密碼:");
scanf("%s",z.b);
p=fopen("m.txt","w+");
fprintf(p,"%s %s",z.a,z.b);
fclose(p);
printf("修改成功!");

}

}
else printf("密碼錯誤!");
}
else printf("用戶名錯誤");
fclose(p);

}

}

H. C語言用c寫一個可以驗證賬號,密碼和修改密碼的程序

#include <string.h>
struct e
{
char a[10];
char b[10];
}z;
int main()
{ int t=0;
char s[10],d[10];
FILE *p;
void as();
if ((p=fopen("m.txt","r+"))==NULL)
{
p=fopen("m.txt","w+");
t=1;
}
if(t==1)
{
printf("當前沒有任何用戶\n");
printf("請新建用戶名: ");
scanf("%s",s);
printf("為用戶設置密碼: ");
scanf("%s",d);
strcpy(z.a,s);
strcpy(z.b,d);
fprintf(p,"%s %s",z.a,z.b);
fclose(p);
}
if(t==0)
{
printf("請輸入用戶名: ");
scanf("%s",s);
fscanf(p,"%s %s",z.a,z.b);
fclose(p);
if (!strcmp(z.a,s))
{
printf("請輸入密碼:");
scanf("%s",d);getchar();
if(!strcmp(z.b,d))
{ char i;
printf("是否要修改密碼?(輸入y修改,n退出!)");
scanf("%c",&i);
if(i=='y')
{
printf("請輸入修改密碼:");
scanf("%s",z.b);
p=fopen("m.txt","w+");
fprintf(p,"%s %s",z.a,z.b);
fclose(p);
printf("修改成功!");
}
}
else printf("密碼錯誤!");
}
else printf("用戶名錯誤");
fclose(p);
}
}

I. 如何用c語言來編一個簡單的密碼程序

這個問題很難解釋啊~如果最簡單的說,你有一個固定的密碼,比如123
那麼直接就是
if(password==123){
//你要輸出的正確信息,比如cout
?????????
}
else{
//錯誤信息
}
復雜來說,你的密碼可能存放在一個資料庫中,你就要先在資料庫中查找對應的用戶名,再核對密碼
此外,密碼一般是不能直接保存的,會被看到,所以你要有個加密的演算法來保存你的密碼,簡單來說,你把正確的密碼加密後保存,你等他輸入一個密碼,你用同樣的演算法加密,再和你的保存的加密過的比較就OK了

J. 如何使用c語言編寫一個密碼程序

密碼保存在文件中,從文件中讀取密碼,但是沒做容錯和異常處理,僅供參考

#include <stdio.h>
#include <string.h>

#define PSDLEN 6

void inputPsd(char *str) /*處理輸入*/
{
int i;

for(i = 0; i < PSDLEN; i++)
{
while(1)
{
str[i] = getch();
if(str[i] == '\b') /*處理退格鍵*/
{
i--;
if(i < 0)
{
i = 0;
}
else
{
printf("\b \b");
}
continue;
}
else if(str[i] == '\r') /*處理回車鍵*/
{
continue;
}
else
{
printf("*");
break;
}
}
}
str[i] = '\0';
printf("\n");
}

int checkFirst() /*檢測是否是第一次使用*/
{
FILE *fp;
if((fp = fopen("psd.dat", "rb")) == NULL)
{
return 1;
}
fclose(fp);
return 0;
}

void firstUse() /*第一次使用 需要輸入密碼*/
{
FILE *fp;
int i;
char passwd[PSDLEN + 1];
char checkPsd[PSDLEN + 1];

if((fp = fopen("psd.dat", "wb")) == NULL)
{
printf("Creat password error!\n");
exit(1);
}
while(1)
{
printf("Please input password:");
inputPsd(passwd);

printf("\nPlease input password again:");
inputPsd(checkPsd);

if(!strcmp(passwd, checkPsd))
{
break;
}
printf("\ncheck password error! \n");
}
fwrite(passwd, sizeof(char), PSDLEN, fp);
fclose(fp);
}

void login() /*核對密碼,並登錄*/
{
FILE *fp;
int i, num = 3;
char passwd[PSDLEN + 1];
char checkPsd[PSDLEN + 1];

if((fp = fopen("psd.dat", "rb")) == NULL)
{
puts("Open psd.dat error");
exit(1);
}
fread(passwd, sizeof(char), PSDLEN, fp);
fclose(fp);
passwd[PSDLEN] = '\0';

printf("Please input password to login");
while(num)
{
printf("you have %d chances to cry:\n", num);
inputPsd(checkPsd);
if(!strcmp(passwd, checkPsd))
{
break;
}
puts("\npassword error,Please input again");
num--;
}
if(!num)
{
puts("Press any key to exit...");
getch();
exit(0);
}
else
{
puts("\n--------\nWelcome!\n--------\n");
}
}

void main()
{
if(checkFirst())
{
firstUse();
}
else
login();

getch();
}