Write a program to take password in C language

Every one is aware about password,today I am going to cover a program "How to read password in C language?" In exam  this question is normally asked many time specially in first year of engineering.To understand the program first we will take the input from the user  as passoword in asterisk (*) and print same password as string on screen.


Below is the program -
C program to take password from user
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<stdio.h>
#include<conio.h>
 
int main() {
   char password[128], c;
   int index = 0;
   
   printf("Enter Password : ");
   /* 13 is ASCII value of Enter key */
   while((c = getch()) != 13){
       if(index < 0)
           index = 0;
       /* 8 is ASCII value of BACKSPACE character */
       if(c == 8){
           putch('\b');
           putch(NULL);
           putch('\b');
           index--;
       continue;
       }
       password[index++] = c;
       putch('*');
   }
   password[index] = '\0';
  
   printf("\nMy Password is = %s", password);
   
   return 0;
}

Output:

Enter Password : **********
My Password is= codibucket



I hope you have understand the program. I would like to have feedback from you. Your feedback, question ,queries or comments  are always welcome.

Thanks.
Write a program to take password in C language Write a program to take password  in C language Reviewed by CodiBucket on 10:24 Rating: 5

No comments:

Powered by Blogger.