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("