Home › Forums › Programming › Password Validation Using C: getch()
- This topic has 0 replies, 1 voice, and was last updated 13 years, 4 months ago by Basavaraj.
Viewing 1 post (of 1 total)
- AuthorPosts
- January 11, 2012 at 3:00 pm#1010BasavarajMember
- #include<stdio.h>
- void main()
- {
- char pwd[20]="Oracle"; // your password.
- char ent_pwd[20]; // The typed password will be stored in this array.
- char ch;
- int i=0; // used refer array index.
- printf("Enter the password : ");
- while( (ch=getch()) !='\r' ) // getch() is used to read the char soon after pressing the key.
- {
- ent_pwd[i++]=ch;
- printf("*"); // '*' is echoed for each keypress
- }
- ent_pwd[i]='\0'; // assign null char to string( user entered password ).
- if( strcmp(pwd,ent_pwd)==0 ) // if password matched
- printf("\nLogin success full");
- else
- printf("\nLogin failed");
- getch(); // here getch() is used to go to user screen.( general use of getch() )
- }
#include<stdio.h> void main() { char pwd[20]="Oracle"; // your password. char ent_pwd[20]; // The typed password will be stored in this array. char ch; int i=0; // used refer array index. printf("Enter the password : "); while( (ch=getch()) !='\r' ) // getch() is used to read the char soon after pressing the key. { ent_pwd[i++]=ch; printf("*"); // '*' is echoed for each keypress } ent_pwd[i]='\0'; // assign null char to string( user entered password ). if( strcmp(pwd,ent_pwd)==0 ) // if password matched printf("\nLogin success full"); else printf("\nLogin failed"); getch(); // here getch() is used to go to user screen.( general use of getch() ) }
Note : getch() is unformatted unbuffered character input function,unbuffered means the char typed will read readily without waiting for enter key to be pressed.
- AuthorPosts
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.