当前位置:首页 » 密码管理 » 如何用语言编译密码

如何用语言编译密码

发布时间: 2022-07-07 09:14:30

‘壹’ 用c语言做一个输入密码程序

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

‘贰’ 如何使用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语言来编辑最简单的输入密码程序

改了下楼上的写的
#include
void
main(void)
{
int
i,a;
char
b[20];;
i=0;
printf("请输入密码:\t");
while((a=getch())!='\r')
{if(a==8){i--;printf("%c
%c",a,a);continue;}
b[i]=a;
printf("*");
i++;
}
b[i]='\0';
printf("\n输入完毕\n");
printf("密码是:
%s\n",b);
getch();
}
最后两个打印可以不要

‘陆’ 请教高手如何用C语言译密码

专业加密,一般专门定义一个头文件,里面是一些数组,
数组里面都是对加密的初始化。
然后再通过一些方法调用初始化的加密。
这个比较复杂。
如果只是简单的添加一个密码,
那就把密码保存到一个字符串里面,然后让用户输入字符,
如果跟定好的字符符合,那么就通过,这个就非常简单了。

‘柒’ 如何用易语言编一个密码程序,写入密码正确才能打开程序

打开易语言
先别点WINDOWS窗口程序
先点下通用向导创建-常用向导
然后再点
通用密码登陆管理向导
下面就添添表单
一个你想要的要输入用户名和密码的程序就算创建出来了

‘捌’ 如何用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("对不起,密码输入错误! ");

}

‘玖’ 请大神帮我用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]={''};
charDataFile[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语言编译一个密码程序,错误可再输入(最多三次)

main()
{
int i;
char *pwd = "123456";
char pwd2[7];
for (i=0; i<3; i++)
{
printf("请输入密码:");
scanf("%s", pwd2);
if (strcmp(pwd, pwd2)==0)
{
break;
}
else
{
printf("您已错误%d次(共3次)", i+1);
}
}

if (i<3) printf("登录成功!\n");
else printf("密码错误3次,系统锁定!\n");
}

热点内容
索尼手机为什么不能用安卓10 发布:2025-05-16 05:18:46 浏览:783
蔚来es6选择哪些配置实用 发布:2025-05-16 05:18:05 浏览:129
小米如何扫码wifi密码 发布:2025-05-16 05:13:38 浏览:806
楼层密码是什么意思 发布:2025-05-16 05:13:37 浏览:12
创建文件夹失败 发布:2025-05-16 05:12:59 浏览:395
电脑上如何查询自己的配置 发布:2025-05-16 05:06:36 浏览:104
sql中去重 发布:2025-05-16 04:55:06 浏览:893
dwr上传图片 发布:2025-05-16 04:49:46 浏览:121
base64加密的图片 发布:2025-05-16 04:35:46 浏览:355
数据结构c语言版清华大学出版社 发布:2025-05-16 04:30:44 浏览:274