当前位置:首页 » 编程语言 » 怎么用c语言编译密码
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

怎么用c语言编译密码

发布时间: 2023-04-10 17:55:45

㈠ 用c语言编写一个设置密码的程序

#include "stdio.h"
int* set(void);
int* set(void)
{
int i;
static a[4];
printf("请输入要设置的4位密码 :");
for(i=0;i<4;i++)
{
scanf("%d",&a[i]);
}
return a;
}

int main()
{
int i,*a,b[4];
a=set();
printf("请输入4位密码 :");
for(i=0;i<4;i++)
{
scanf("%d",&b[i]);
}
i=0;
while(i<4)
{
if(a[i]==b[i])
{
printf("%d",a[i]);
i++;
}
else
{
break;
}
}
if(i==4)
{
printf("密码正确\n");
}
else
{
printf("密码错误\n");
}
return 0;

}

㈡ 如何使用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();
}

㈢ 如何编译一个C语言密码程序,判断密码的位数(如5位),如果输入的密码小于5位或者大于五位都有相应提示

代码如下:

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

intmain()
{
intlen=0;
charpassword[10]={0};

printf("请输入密码:");
scanf("%s",password);

len=strlen(password);

if(len<5){
printf("密码长度不足! "扮顷);
}
elseif(len>5){
printf("密码长度过长! ");
}
else{

//默认密码是银轮admin
if(strcmp(password,"admin")==0){
printf("登录成功! ");
}
else{
printf("密码不锋缺信正确! ");
}
}

system("pause");
return0;
}

㈣ 如何用c语言编写英文密码还要判断正不正确的那种

#include <stdio.h>

#include <string.h>

int main()

{

char a[100],*b="miku";

改猜 gets(a);

if(strncmp(a,b,strlen(b))==0)

puts("yes");

核毕型 else

数者 puts("no");

return 0;

}

㈤ 请教高手如何用C语言译密码

读出每个字符,然后给它加上4就可以了,如果要还原,就用每个字符减去4.

㈥ 悬赏100分 如何用c语言 写一个密码程序

clude "string.h"

//考虑到用数据库文件保存注册信息的话要使用access创建文件并且还要配置数据源,所以我的方法是采用将注册信息保存到文件
//下面是完整的程序:

//登陆检测函数
int login(char *name,char *password)
{
char info[10000];
char *p=info;
FILE *file=fopen("user","r");
int size;
if(file)
{
size=fread(info,1,10000,file);
while(size!=(int)p-(int)info)
{
if(!strcmp(p,name)&&!strcmp(p+strlen(p)+1,password))
{
fclose(file);
return 1;
}
p+=strlen(p)+1;
p+=strlen(p)+1;
}
}
fclose(file);
return 0;
}

//添加注册信息入文件
void save(char *name,char *password)
{
FILE *file=fopen("user","a");
fwrite(name,1,strlen(name)+1,file);
fwrite(password,1,strlen(password)+1,file);
fclose(file);
}

#define PASSWORD "12345" //这里指定你要允许通过的密码,比如12345,将引号里的数字改为你想要的即可
int main()
{
char password[100];
char name[100],c[100],password1[100];
tag1: printf("press 1 to register, or 2 to login\n");//输入1为注册,输入2为登陆
while(1)
{
gets(c);
if('1'==c[0])
{
printf("please enter your name\n");//输入姓名
gets(name);
tag2: printf("please enter your password\n");//输入密码
gets(password);
printf("please enter your password again\n");
gets(password1);
if(strcmp(password,password1))
{
//两次密码不一致,重输
printf("the password you entered is different from the first one,please try again!\n");
goto tag2;
}
printf("register is completed!\n");//注册成功
//下面实现将注册信息加入文件保存
save(name,password);
goto tag1;
}
else if('2'==c[0])
{
tag3: printf("please enter your name:\n");
gets(name);
printf("please enter your password:\n");
gets(password);
if(login(name,password))//如果验证通过,则
{
printf("login successfully!\n");

//这里添加成功登陆后要执行的代码
}
else
{
printf("your name or password doesn't exist!\n");//否则重输
goto tag3;
}

}
else
{
printf("invalid input!press 1 to register, or 2 to login\n");//输入非法,重输
goto tag1;
}

}

return 0;
}

饿,写了我两个小时啊,大哥,分一定要给我啊~~~~~~

㈦ 请大神帮我用C语言编译一有关于密码的程序。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<windows.h>

typedefstruct
{
intx;
inty;
}PT_STRUCT;

typedefstruct
{
charuser[20];
charpw[20];
}USER_STRUCT;

PT_STRUCTpt;
boolLoginSuccess=false;
charCurrentUser[20]={''};
intUserCount=0;
intLoginErrCount=0;
USER_STRUCT*pUser=NULL;
charWorkDir[100]={''};
char档岩漏DataFile[100]={''};

voidsetxy(intx,inty)
{
COORDcoord={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}

voidgetxy()
{
HANDLEhConsole=GetStdHandle(STD_OUTPUT_HANDLE);
COORDcoordScreen={0,0};//光标位置
CONSOLE_SCREEN_BUFFER_INFOcsbi;
if(GetConsoleScreenBufferInfo(hConsole,&csbi))
{
pt.x=csbi.dwCursorPosition.X;
pt.y=csbi.dwCursorPosition.Y;
}
}

voidinput(char*buf)
{
intlen=strlen(buf);
intc;
inti=0;
while(1)
{
c=getch();
if(c==8&&i==0)
{
continue;
}
if(c==10||c==13) break;
if(c==8&&i>0)
{
buf[i-1]='';
i--;
getxy();
setxy(pt.x-1,pt.y);
printf("");
setxy(pt.x-1,pt.y);
}
elseif(i>=0)
{
printf("*");
buf[i++]=c;
}
if(i>=buf)
{
return;
}
}
}

voidGetUserDataFromFile()
{
UserCount=GetPrivateProfileInt("USER","user_count",0,DataFile);
if(pUser!=NULL)
{
free(pUser);
}
pUser=(USER_STRUCT*)malloc(sizeof(USER_STRUCT)*(UserCount+1));
inti;
charch[5];
for(i=0;i<UserCount;i++)
{
memset(ch,'',5);
sprintf(ch,"%d",i+1);
GetPrivateProfileString(ch,"user","",pUser[i].user,20,DataFile);
GetPrivateProfileString(ch,"pw","",pUser[i].pw,20,DataFile);
}
}

voidWriteDataToFile()
{
inti;
chart[5]={""};
sprintf(t,"%d",UserCount);
WritePrivateProfileString("USER","user_count",t,DataFile);
for(i=0;i<UserCount;i++)
{
sprintf(t,"%d"行烂,i+1);
WritePrivateProfileString(t,"user",pUser[i].user,DataFile);
WritePrivateProfileString(t,"pw",pUser[i].pw,DataFile);
}
GetUserDataFromFile();
}

boollogin()
{
if(LoginSuccess==true)
{
printf("当前枣郑已有用户登录!重新登录吗?(Y/N)");
charsel;
fflush(stdin);
scanf("%c",&sel);
if(sel=='y'||sel=='Y')
{
LoginSuccess==false;
}
else
{
returnfalse;
}
}
charuser[20]={''};
charpw[20]={''};
printf(" InputUser:");
fflush(stdin);
scanf("%s",user);
printf(" InputPassword:");
fflush(stdin);
input(pw);
boolfind=false;
inti;
for(i=0;i<UserCount;i++)
{
if(strcmp(user,pUser[i].user)==0&&strcmp(pw,pUser[i].pw)==0)
{
find=true;
LoginSuccess=true;
strcpy(CurrentUser,pUser[i].user);
break;
}
}
if(find==true)
{
return1;
}
else
{
return0;
}
}

boolregist(char*ErrBuf)
{
charuser[20]={''};
charpw1[20]={''};
charpw2[20]={''};
printf(" InputUser:");
fflush(stdin);
scanf("%s",user);
inti;
for(i=0;i<UserCount;i++)
{
if(strcmp(user,pUser[i].user)==0)
{
strcpy(ErrBuf,"UserRepeat");
returnfalse;
}
}
printf(" InputPassword:");
fflush(stdin);
input(pw1);
printf(" ReInputPassword:");
fflush(stdin);
input(pw2);
if(strcmp(pw1,pw2)!=0)
{
strcpy(ErrBuf,"PasswordDiffer");
returnfalse;
}
strcpy(pUser[UserCount].user,user);
strcpy(pUser[UserCount].pw,pw1);
UserCount++;
returntrue;
}

intmain()
{
_getcwd(WorkDir,100);//取得当前程序的绝对路径
strcpy(DataFile,WorkDir);
strcat(DataFile,"\user.dat");
if(access(DataFile,0))
{
printf(" 用户数据文件不存在,按任意键将创建文件");
getchar();
FILE*fp;
fp=fopen(DataFile,"wb");
intre=fputs("[USER] user_count=0",fp);
if(re>=0)
{
printf(" 用户数据文件创建成功!");
}
else
{
printf(" 用户数据文件创建失败!");
}
getchar();
fclose(fp);
}
GetUserDataFromFile();
while(1)
{
system("cls");
printf("已注册用户%d",UserCount);
if(LoginSuccess==true)
{
printf("LoginedUser:%s",CurrentUser);
}
printf(" -------------------------------");
printf(" 登录---1");
printf(" 注册---2");
printf(" 退出---3");
printf(" -------------------------------");
printf(" PleaseInput1-3:");
intsel;
boolre;
charErrBuf[50]={''};
fflush(stdin);
scanf("%d",&sel);
if(sel<1||sel>3)
{
printf(" Inputerror!");
fflush(stdin);
getchar();
continue;
}
switch(sel)
{
case1:
re=login();
if(re==true)
{
printf(" LoginSuccess!CurrentUser:%s",CurrentUser);
fflush(stdin);
getchar();
}
else
{
printf(" LoginFail!");
LoginErrCount++;
if(LoginErrCount>=3)
{
printf(" LoginFail3,Programwillbeexit!");
}
fflush(stdin);
getchar();
if(LoginErrCount>=3)
{
exit(0);
}
}
break;
case2:
memset(ErrBuf,'',50);
re=regist(ErrBuf);
if(re!=true)
{
printf(" %sRegisterFail!",ErrBuf);
fflush(stdin);
getchar();
}
else
{
WriteDataToFile();
printf(" RegisterSuccess!");
fflush(stdin);
getchar();
}
break;
case3:
exit(0);
break;
default:

break;
}
}
return0;
}

㈧ 一个两位纯数字密码破解程序怎么编,用C语言

1、数据范围小的密码可以使用穷举法。这里从00到99,当作字符来处理,需要两重循环。

2、例程:

chara,b,c='1',d='2';//这里变量c,d表示密码的第一位和第二位。
charkey[2];
for(a='0';a<='9';a++){
for(b='0';b<='9';b++){
key[0]=a;
key[1]=b;//这就是一个密码
if(key[0]==c&&key[1]==d)printf("密码是:%s",key);//找到密码并输出
}
}

㈨ 写一个用c语言转换密码的程序

#include<stdio.h>
#include<string.h>
voidmain()
{
inti,n;charstr[21];
gets(str);n=strlen(str);
if(n==0)printf("error");
for(i=0;i<n;i++)
if((str[i]<'a'尘好||str[i]>'z')&&(str[i]<'A'||str[i]>'Z'))
printf("error");
else
{
for(i=0;i<n;i++)
{
if((str[i]>='x'&&str[i]<='z')||(str[i]>派晌铅='X'&&str[i]<='Z'))
str[i]-=22;
elsestr[i]+=4;
printf("%c"谨亮,str[i]);
}
}
}

㈩ 用C语言做一个输入密码程序

以gcc编译器为例,可以分为四步。
第一步是预处理,包括语法检查等工作。
gcc
-p
abc.c
第二步由源程序生产汇编语言代码。
gcc
-s
abc.c
会生成abc.s文件,这个文件里就是汇编代码。
第三步编译器生成目标代码,一个源文件生成一个目标代码。
gcc
-c
abc.c
会生成abc.o
第四步连接器从目标代码生成可执行文件。
gcc
abc.o
目标代码包括机器码和符号表(函数及变量名)。连接器的主要作用是通过符号表在库文件和其他模块中找到在目标代码中引入或未定义的符号(函数及变量名),将几个目标代码合成可执行文件。