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

c語言驗證用戶密碼

發布時間: 2022-08-22 02:26:23

『壹』 用c語言:根據給定的演算法,判斷輸入的密碼是否正確

#include<stdio.h>
void main()
{
int n,password=123456,i=1;
while(1)
{
printf("輸入密碼:");
scanf("%d",&n);
if(n==password)
printf("Welcome to use the software\n");
else
{
if(i<3)
printf("剩餘的可輸入密碼的次數為:%d\n",3-i);
else
printf("Password error ! You can not use the software\n");
i++;

}
if(i>=4||n==password)break;
}
}
這個是不需要用return的,簡明一點,初學的應該會

『貳』 C語言密碼驗證問題(程序設計求改)

1 b[8] 定義一個數組變數b,佔用8個位元組

你想要從鍵盤輸入8個字元,通過gets函數接收數據。

但是,gets內部是這么乾的:

不管你輸入幾個字元,都要在末尾補一個''

從鍵盤接收了8個字元放入數組b以後,b就被占滿了,補的0就順序放在了數組b的外邊。恰好,數組b的外面就是數組a,補的0擠佔了數組a的第一個位元組。

然後無論怎麼比較,這兩個數組都是不等的,結果就是wrong

-----------

把數組b的空間定義的大一點,比如b[1000],要定義的足夠大,讓鍵盤怎麼輸入都占不滿。

『叄』 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);
}
}

『肆』 C語言用字元串比較函數驗證賬號和密碼

#include <string.h>
char user[]="輸入的帳號", pwd[]="輸入的密碼";
if (strcmp("真實帳號", user) == 0 && strcmp("對應密碼", pwd) == 0) {
printf("驗證成功!");
} else {
printf("帳號或密碼錯誤!");
}

『伍』 c語言 密碼驗證

用getch()非回顯函數就可以了

#include <stdio.h>
#include <conio.h>
char mypw[10]="123";//預先設定的密碼
int check(char a[])
{
int len=0;
while(len<10&&a[len]!=0x0d&&a[len]!='\0')
{
if(mypw[len]!=a[len]) return 0;
len++;
}
return 1;
}

int main()
{
char pw[10];//用戶輸入的密碼
int i;
for(i=0;i<10;i++) pw[i]='\0';
int len=0;
printf("輸入密碼\n");
while(len<10&&0x0d!=(pw[len]=getch()))//用getch()非回顯函數
{
len++;
printf("*");
}
printf("\n");
if(check(pw)) printf("密碼正確");
else printf("密碼錯誤");
getchar();
return 0;
}

『陸』 C語言編寫一個密碼驗證程序。

#include<stdio.h>
#include<conio.h>
voidmain()
{
charexp1='1',exp2='2',exp3='3';//預期值
charch1,ch2,ch3;
ch1=getch();
printf("*");

ch2=getch();
printf("*");

ch3=getch();
printf("* ");
if(ch1==exp1&&ch2==exp2&&ch3==exp3)
{
printf("歡迎進入系統 ");
}
else
{
printf("密碼輸入錯誤,請退出 ");
}
}

『柒』 C語言的密碼檢測怎麼做

conio.h不是c標准頭文件,建議不要用這個頭文件。把這個頭文件刪掉。

將讀入密碼那行的函數改用gets

gets(input_pass);

另外為了避免bug,input_pass最好弄大一點。

『捌』 C語言中密碼校驗怎麼做

給你個參考:

#include<stdio.h>
#include<conio.h> //用getch()函數時要的文件頭
#include<string.h>

#define USER "admin"
#define PWD "admin"

void main()
{
char user[20], pwd[16], ch;
int count=0, i=0;
while(count<3) //3次機會輸入正確密碼
{
printf("user name:");
gets(user);
printf("password:");
while((ch=getch())!=13&&i<16) //將輸入的密碼轉換成字元****
{
putchar('*');
pwd[i]=ch;
i++;
}
pwd[i]=0;
if(!strcmp(USER,user)&&!strcmp(PWD,pwd))
break;
else
printf("\nincorrect user name or password!\n");
count++;
}
printf("\nlogin successful!\n");
}

『玖』 c語言編程 用戶登錄驗證密碼

//核心代碼如下

//定義計數變數
intcount=0;

if(登錄失敗)
{
count++;
if(count>=3)
{
printf("不給進入");
//視情況而定是否需要重置count的值
count=0;
}
}

『拾』 用C語言編寫一個密碼驗證程序

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

typedef struct
{
long number; //用戶編號 6位
char name[20]; //用戶名
char password[8]; //用戶密碼
int power; //許可權判斷 1 為管理員2為普通用戶
} user;
user yh[100]={100000,"gavin","gavine",1,100001,"wnag","wangf",2};
int length = 2;

int checkuser(long num, const char *nm, const char *pwd)
{
int i;
for (i = 0; i < length; ++i)
{
if (yh[i].number == num && !strcmp(yh[i].name, nm) && !strcmp(yh[i].password, pwd))
{
if (1==yh[i].power)
return 1;
else
return 2;
}
}
}

void main()
{
printf("%d\n", checkuser(100000, "gavin", "gavine"));
}