| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
General - Preventing program from displaying its password
Hi I am a beginner with C++ and I created a program to convert currency. The problem is that i created it to ask for a password before the program can be run but it shows the password after it is enter. so, when the program is run, it asks for the password and if it is correct it will continue the program but the password remains visible. Is there a way I can prevent this?
Thanks for any help at all. |
|
#2
|
|||
|
|||
|
you can use _getch() in a loop from conio.h to not display the password completely or you can use system("cls") for windows or system("clear") for linux using cstdlib
eg1: Code:
#include <iostream>
#include <conio.h>
#include <string>
int main()
{
std::string password;
std::string tmp;
password.clear();
char pass;
std::cout << "Password: ";
while (pass = _getch())
{
if ((pass == 10) || (pass == 13))
break;
tmp = pass;
password.append(tmp);
tmp.clear();
}
/*
password is now the password
*/
/*...*/
return 0;
}
eg2: Code:
#include <cstdlib>
/*...*/
system("cls");
/*...*/
Last edited by kotarou3 : June 20th, 2009 at 08:33 AM. Reason: fix |
|
#3
|
|||
|
|||
|
Hi thank for the reply. in example 1 they say invalid conversation between char and constant char. The 'password.append(pass);' is the only thing that is highlighted. What does this mean?
Thank You. |
|
#4
|
|||
|
|||
|
Whoops, bad code. not even std:: before string. I was in a hurry in the previous post.
Here, code that i tested that it works: Code:
#include <iostream>
#include <conio.h>
#include <string>
int main()
{
std::string password;
std::string tmp;
password.clear();
char pass;
std::cout << "Password: ";
while (pass = _getch())
{
if ((pass == 10) || (pass == 13))
break;
tmp = pass;
password.append(tmp);
tmp.clear();
}
/*
password is now the password
*/
/*...*/
return 0;
}
|
|
#5
|
|||
|
|||
|
works
Thanks man system("cls") works good.
Is there way that I can get a GUI for my C++ program? I don't know how to program in GUI. Thanks |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > General - Preventing program from displaying its password |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|