password.cpp

来自「Hotel Management System in c++」· C++ 代码 · 共 72 行

CPP
72
字号
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void login()
{

 int attempt=1,curr_y=20,chrent=0;
 char password[]={"start"};
 char upass[7],chr;
 while(attempt<=3)
 {
  if(attempt>1)
   printf("\a");
  gotoxy(20,curr_y);
  cprintf("Enter your CURRENT password : ");
  while(chrent<=6)
  {
   chr=getch();
   if(chrent==6 && chr!=13)
   {
    if(chr==8)
    {
     printf("\b \b");
     chrent--;
     continue;
     }
    printf("\a");
    continue;
    }
   if(chr==13)
   {
    upass[chrent]='\0';
    if(strcmp(password,upass)==0)
    {
     gotoxy(30,10);
     cprintf("LOGIN SUCCESS ");
     return;
    }
    else
    {
     chrent=0;
     attempt++;
     curr_y++;
     break;
    }
   }
   if(chrent<6 && chrent>=0)
   {
    if(chr==8)
    {
     if(chrent>0)
     {
     printf("\b \b");
     chrent--;
     }
     else
      printf("\a");
     continue;
     }
    else
    {   upass[chrent++] = chr;
	printf("*");
    }
   }
  }  //while closed
 } // main while closed
 gotoxy(20,10);
 cprintf("LOGIN FAILED .... Press Any key to shut down");
 getch();
 exit(0);
 }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?