By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

How to take passwords input as ****** or just nothing

P: 52
Hello,
I am making a console application in C++ where I have to take username and password as input from user.
I want that when password is taken, it should not be shown on screen, i.e. it is either shown as asterix(*******) or just no movement of cursor.

Please Reply
Pawan
Mar 10 '07 #1
Share this Question
Share on Google+
6 Replies


Expert 100+
P: 1,510
Hello,
I am making a console application in C++ where I have to take username and password as input from user.
I want that when password is taken, it should not be shown on screen, i.e. it is either shown as asterix(*******) or just no movement of cursor.

Please Reply
Pawan
some windows compilers have a header file <conio.h> with a function getch() which reads a character from the keyboard without echo .
Mar 10 '07 #2

100+
P: 180
some windows compilers have a header file <conio.h> with a function getch() which reads a character from the keyboard without echo .
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.    char ch;
  4.    string password;
  5.    while ( (ch = getch()) != '\r' )
  6.    {  
  7.          password.push_back(ch);
  8.    }
  9.    cout<< "You entered :"<< password<<endl;
  10.    return 0;
  11. }
You can use above code for windows, For Linux, there is something called getpass( char* ); type man getpass on console to see how it works.
Mar 12 '07 #3

saranjegan
P: 51
Hello,
I am making a console application in C++ where I have to take username and password as input from user.
I want that when password is taken, it should not be shown on screen, i.e. it is either shown as asterix(*******) or just no movement of cursor.

Please Reply
Pawan
use getpass function
or print *** using getch and putch in a for loop
Mar 13 '07 #4

P: 52
use getpass function
or print *** using getch and putch in a for loop
What is this getpass() function, I didnt find it anywhere!
Pawan
Mar 18 '07 #5

P: 52
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.    char ch;
  4.    string password;
  5.    while ( (ch = getch()) != '\r' )
  6.    {  
  7.          password.push_back(ch);
  8.    }
  9.    cout<< "You entered :"<< password<<endl;
  10.    return 0;
  11. }
You can use above code for windows, For Linux, there is something called getpass( char* ); type man getpass on console to see how it works.
Thanks, it worked.
Pawan
Mar 18 '07 #6

P: 1
nice. it works perfectly!!! thx, i've been searchin ds codes for ages..
Mar 19 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.