Password Validation Using C: getch()

Home Forums Programming Password Validation Using C: getch()

Tagged: , ,

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1010
    Basavaraj
    Member
    1. #include<stdio.h>  
    2. void main()  
    3. {  
    4.   char pwd[20]="Oracle";  // your password.  
    5.   char ent_pwd[20];  // The typed password will be stored in this array.  
    6.   char ch;   
    7.   int i=0;  // used refer array index.   
    8.   printf("Enter the password : ");  
    9.   
    10.  while( (ch=getch()) !='\r' )  // getch() is used to read the char soon after pressing the key.  
    11.  {  
    12.     ent_pwd[i++]=ch;  
    13.     printf("*");  // '*' is echoed for each keypress  
    14.  }  
    15.  ent_pwd[i]='\0';  // assign null char to string( user entered password ).  
    16.   
    17.  if( strcmp(pwd,ent_pwd)==0 ) // if password matched  
    18.  printf("\nLogin success full");  
    19.  else  
    20.  printf("\nLogin failed");  
    21.   
    22.  getch();  // here getch() is used to go to user screen.( general use of getch() )  
    23.   
    24. }  

    Note : getch() is unformatted unbuffered character input function,unbuffered means the char typed will read readily without waiting for enter key to be pressed.

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.