?
Solved

C++ Password

Posted on 2003-03-19
3
Medium Priority
?
1,152 Views
Last Modified: 2012-06-21
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.

 
0
Comment
Question by:Sekhar_ee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 8165334
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
 

Accepted Solution

by:
einsamer_schuetze earned 60 total points
ID: 8165581
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
 

Expert Comment

by:TMM
ID: 8169345
Are you using VC++ or Borland or ANSI C++???
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question