Mar 18, 2015 at 10:00am UTC
How can I change the character when typing a password from letter to asterisk(*)? Thanks!
Mar 18, 2015 at 10:36am UTC
I need a bit more information.
How do you get the data input and where do you want the data output?
Mar 18, 2015 at 10:48am UTC
it won't work that way.
simple as that.
the terminal prints the caracters as soon as they are entered
Mar 18, 2015 at 10:56am UTC
So how can I make the displaying password is asterisk rather than letters and numbers?
Mar 18, 2015 at 11:09am UTC
We can't give you a simple answer because there is no way to do what you ask for using only standard C++. Other library/system functions are needed to do it. You can probably find a solution in the links above, but note that many of them does not work on all platforms.
Last edited on Mar 18, 2015 at 11:11am UTC
Mar 18, 2015 at 11:20am UTC
This is my codes so far. The problem is that, when you put wrong password on the first try, then you put the correct password on the second time, it will not recognize the right password.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main()
{
string pass ="" , newPass;
char ch, ch1;
bool isRunning = true ;
cout << "Enter pass: " ;
ch = _getch();
while (ch != 13)
{//character 13 is enter
pass.push_back(ch);
cout << '*' ;
ch = _getch();
}
cout << endl << endl;
do
{
cout << "\n\nEnter your pass: " ;
ch1 = _getch();
while (ch1 != 13)
{//character 13 is enter
newPass.push_back(ch1);
cout << '*' ;
ch1 = _getch();
}
if (pass == newPass)
{
isRunning = false ;
cout << "\n\nAWW!" ;
}
}while (isRunning);
_getch();
return 0;
}
Last edited on Mar 18, 2015 at 11:22am UTC
Mar 18, 2015 at 11:29am UTC
You need to newPass.clear();
before you iterate the next try
Mar 18, 2015 at 11:33am UTC
Yaaaaaay! Thanks Bro coder777. Its working now! :)