0

Hi Again. I have a password field in one of my programs. I would like to display the letters as a *. Does anyone have some code to achieve this?

5
Contributors
6
Replies
8
Views
8 Years
Discussion Span
Last Post by cppnewb
1

I think your going to have to give more detail here...Are you using MFC? If so then a password box will automatically do this....

Again we really need more information

Chris

Votes + Comments
Yes we do :)
0

Like:

string pword;
string pkey = "testing";
cout << "Please enter the password";
<<endl;
cin >> pword;

0

You could do it (quite unstandardly) via

#include <iostream>
#include <string>

// Non-standard library
#include <conio.h>

int main() {
  std::string password;

  std::cout<< "Enter password: ";
  for( char ch=getch(); ch != 0x0D; ch=getch() ) {
    password += ch;
    std::cout<< "*";
  }
  std::cout<< "\nThe password is: " << password << "\n";

  return 0;
}

0x0D is hex for return, I think.

0

> Again we really need more information
Specifically, your operating system and compiler.

And try to be more specific than say "windows" and "borland", as there are many versions of both.

0

Ok, sure thing. I'm using Windows XP and My complier is the one that comes with Dev-C++, Mingw I believe.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.