C Program to mask password text with asterisk(*)

C Program to mask password text with asterisk(*). This program is to illustrate how user authentication is made before allowing the user to access the secured resources. It asks for the user name and then the password. The password that you enter will not be displayed, instead that character is replaced by ‘*’. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                        Happy Coding
***********************************************************/

#include <stdio.h>
#include <conio.h>

void main()
{
 char pasword[10],usrname[10], ch;
 int i;
 clrscr();

 printf("Enter User name: ");
 gets(usrname);
 printf("Enter the password <any 8 characters>: ");

 for(i=0;i<8;i++)
 {
  ch = getch();
  pasword[i] = ch;
  ch = '*' ;
  printf("%c",ch);
 }

 pasword[i] = '';

 /*If you want to know what you have entered as password, you can print it*/
 printf("nYour password is :");

 for(i=0;i<8;i++)
 {
  printf("%c",pasword[i]);
 }
}
Read more Similar C Programs
Searching in C
C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

3 comments on “C Program to mask password text with asterisk(*)

  • Hey this code is not correct.
    While entering password,
    if you press ENTER key also it is printing *.
    if you press BACKSPACE or DELETE or ESC or anything, it is printing *.

    Your code will be valid only if you fix this validations.

    Reply
  • vitabrain says:

    First off I want to say terrific blog! I had a quick question that
    I’d like to ask if you don’t mind. I was interested to know how you center yourself and clear your
    head prior to writing. I have had difficulty clearing my thoughts in getting my ideas out.
    I do take pleasure in writing but it just seems
    like the first 10 to 15 minutes are lost simply just trying to figure out how to begin. Any suggestions
    or hints? Cheers!

    Reply

Leave a Reply