954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Hiding Password on the login screen

Hi All,

I am writing a code in C++ to implement Login screen which will accept user name and password from the user. Now my main concern is to hide that password to be sceen by the user.

suppose my password is "Rat420" so at the time of typing anything i want it to appear as "******".

That means i need "*" to be seen on screen for each and ever character, and the original password is not lost.

RohitSahni
Light Poster
35 posts since Jul 2007
Reputation Points: 25
Solved Threads: 0
 

That depends. What I/O interface are you using?

Is it a console process? Are you using a GUI? What OS? What widget set?

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

There is no way to do this in standard C++. There are non-standard ways to get the job done, some of which are in common use, though. Knowing at least some of the information asked by Duoas will be necessary to try to help inform you of which non-standard methods may be available to you.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

Yes it is a console process.
i am using Unix and using Sun C++ compiler
and also i am using GUI.

RohitSahni
Light Poster
35 posts since Jul 2007
Reputation Points: 25
Solved Threads: 0
 

>>also i am using GUI
You mean the compiler is has a GUI interface ? I think you will probably have to use the curses library.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Agreed. If I remember correctly, the curses library actually has a function that does what you want...

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
 

That code will not work in unix. The idea to use a loop to get characters is fine, but you will still need to use curses to unbuffer your stdin.

(Besides wish, that code is old and non-standards compliant.)

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

There is a Buit in function called getpass in conio.h

Prototype : char *getpass(const char *prompt);

Displays the prompt string and then reads the password without echoing. Returns a pointer to a static string containing the input password.
Usage://include the conio.h and string.h

char a[20];

strcpy(a,getpass("Enter Pass"));
cout<

siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
 

>There is a Buit in function called getpass in conio.h
Maybe on your compiler's flavor of C++. Just because it works for you doesn't mean it works for everyone, so at the very least mention your compiler and OS.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

That will not work in Linux.

The getpass() function is borrowed directly from , and is outdated and unreliable.

Use curses.

[EDIT] Heh, too slow again...

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

You could turn off terminal echoing.

Sturm
Veteran Poster
1,079 posts since Jan 2007
Reputation Points: 343
Solved Threads: 24
 

how to create login in oo c++ using class

shashanderson
Newbie Poster
23 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You