当前位置:首页 » 编程语言 » 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();
}