Powered By Blogger

Utilities

PASSWORD FIELD IN C PROGRAM  

In this section we will create a password field which will replace password characters with  *

You can use this code in terminal base application.

      
SOURCE CODE:

#include<stdio.h>
#define ENTER 13
#define TAB 9
#define BKSP 8

char pwd[100];

int main(){
int i= 0;
char ch;

printf("enter your password.Hit enter to conform.\n");
printf("password:");

while(1){
ch = getch(); //GET KEY

if(ch == ENTER || ch ==TAB)
    {
        pwd[i] = '\0';
break;

}else if(ch== BKSP){
if(i>0){
i--;
printf("\b \b");
}
}else{
 pwd[i++]= ch;
 printf("* \b");
 }
} //while ends here
printf("\n\nPassword:%s \n Length:%d");
return 0;
} //main() ends here

No comments:

Post a Comment