當前位置:首頁 » 編程語言 » 怎麼用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
目標代碼包括機器碼和符號表(函數及變數名)。連接器的主要作用是通過符號表在庫文件和其他模塊中找到在目標代碼中引入或未定義的符號(函數及變數名),將幾個目標代碼合成可執行文件。