2025年3月13日 星期四 甲辰(龙)年 月十二 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > C语言

简单的开机密码程序

时间:01-03来源:作者:点击数:85

简单的开机密码程序:

  • #include "conio.h"
  • #include "string.h"
  • #include "stdio.h"
  • void error()
  • {window(12,10,68,10);
  • textbackground(15);
  • textcolor(132);
  • clrscr();
  • cprintf("file or system error! you can't enter the system!!!");
  • while(1); /*若有错误不能通过程序*/
  • }
  • void look()
  • {FILE *fauto,*fbak;
  • char *pass="c:\\windows\\password.exe"; /*本程序的位置*/
  • char a[25],ch;
  • char *au="autoexec.bat",*bname="hecfback.^^^"; /*bname 是autoexec.bat 的备份*/
  • setdisk(2); /*set currently disk c:*/
  • chdir("\\"); /*set currently directory \*/
  • fauto=fopen(au,"r+");
  • if (fauto==NULL)
  • {fauto=fopen(au,"w+");
  • if (fauto==NULL) error();}
  • fread(a,23,1,fauto); /*读取autoexec.bat前23各字符*/
  • a[23]='\0';
  • if (strcmp(a,pass)==0) /*若读取的和pass指针一样就关闭文件,不然就添加*/
  • fclose(fauto);
  • else
  • {fbak=fopen(bname,"w+");
  • if (fbak==NULL) error();
  • fwrite(pass,23,1,fbak);
  • fputc('\n',fbak);
  • rewind(fauto);
  • while(!feof(fauto))
  • {ch=fgetc(fauto);
  • fputc(ch,fbak);}
  • rewind(fauto);
  • rewind(fbak);
  • while(!feof(fbak))
  • {ch=fgetc(fbak);
  • fputc(ch,fauto);}
  • fclose(fauto);
  • fclose(fbak);
  • remove(bname); /*del bname file*/
  • }
  • }
  • void pass()
  • {char *password="88888888";
  • char input[60];
  • int n;
  • while(1)
  • {window(1,1,80,25);
  • textbackground(0);
  • textcolor(15);
  • clrscr();
  • n=0;
  • window(20,12,60,12);
  • textbackground(1);
  • textcolor(15);
  • clrscr();
  • cprintf("password:");
  • while(1)
  • {input[n]=getch();
  • if (n>58) {putchar(7); break;} /*若字符多于58个字符就结束本次输入*/
  • if (input[n]==13) break;
  • if (input[n]>=32 && input[n]<=122) /*若字符是数字或字母才算数*/
  • {putchar('*');
  • n++;}
  • if (input[n]==8) /*删除键*/
  • if (n>0)
  • {cprintf("\b \b");
  • input[n]='\0';
  • n--;}
  • }
  • input[n]='\0';
  • if (strcmp(password,input)==0)
  • break;
  • else
  • {putchar(7);
  • window(30,14,50,14);
  • textbackground(15);
  • textcolor(132);
  • clrscr();
  • cprintf("password error!");
  • getch();}
  • }
  • }
  • main()
  • {look();
  • pass();
  • }

 

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门