C++ Password

Hi ,

In C++, I want to write one password program.
I mean , when I am entering the password through console the characters should not display on the screen . While entering the input string how to mask this input with out displaying on the console.

 
Sekhar_eeAsked:
Who is Participating?
 
einsamer_schuetzeConnect With a Mentor Commented:
hi,

try this (mayankeagle's idea in sourcecode :D)

[SOURCE]

#include <stdio.h>               //for printf()
#include <conio.h>               //for _getch()

int main()
{
     char     password[64];
     int          count;

     printf("Please insert password : ");

     count = 0;                                   //counter reset

     while(true)
     {
          password[count] = _getch();          //fetching of input (ASCII)

          if(password[count] == 13 ||          //if ENTER (ASCII '13') or array is full
             count == 63)
          {
               password[count] = '\0';          //setting the array delimiter
               break;                              //end of while
          }

          printf("*");
          count ++;
     }

     printf("\n\nYou've entered : \"%s\"\n",password);

     return 0;
}

[/SOURCE]

greetings from germany (GMT+1)11:38AM


0
 
Mayank SAssociate Director - Product EngineeringCommented:
Read the characters in an array using getch () (so that they are not displayed on the screen) and for each character typed, print a '*' character using cout.

Mayank.
0
 
TMMCommented:
Are you using VC++ or Borland or ANSI C++???
0
All Courses

From novice to tech pro — start learning today.