Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

unknown.exe

macrumors member
Original poster
Sep 22, 2007
67
0
Somewhere on Earth
Sup, I'm trying to make it so that when someone inputs a password into my program, the input is replaced with asterisks as they type, like most computers do. Does anyone know how I can accomplish this? Here is the code that asks for and compares the password:
--------------------------------------------------------------------------
int main()
{
{
int password;
int numtries = 0;
{
cout << "PLEASE TYPE IN THE PASSWORD...\nPASSWORD: ";
password:
cin >> password;
cerr << "LOGGING IN";
sleep(1);
cerr << ".";
sleep(1);
cerr << ".";
sleep(1);
cerr << ".\n";
sleep(1);
if (password == 2090407)
{
cout << "PASSWORD VERIFIED...\n";
goto verystart;
}
else
{
numtries = numtries + 1;
if (numtries == 5)
{
cout << "PASSWORD DENIED...\nSYSTEM LOGGING OUT...\n";
return 0;
}
}
cout << "PASSWORD DENIED, PLEASE TRY AGAIN...\n";
goto password;
}
-------------------------------------------------------------------------------
I'd appreciate any help. Thanks.:apple:
 

yeroen

macrumors 6502a
Mar 8, 2007
944
2
Cambridge, MA
this is what you want: the function readpassphrase from <readpassphrase.h>

just do a man on readpassphrase for more info
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Uuuummmm, the readpassphrase sounds promising, but can anyone give me a real example of how to do wut i'm tryin 2 do?

Code:
#include <stdio.h>
#include <readpassphrase.h>

int main()
{
	const int passwordLength = 20;
	char password[passwordLength];
	readpassphrase("Enter the password: ", password, passwordLength, 0);
	printf("You entered: %s\n", password);
	
	return 0;
}
 

unknown.exe

macrumors member
Original poster
Sep 22, 2007
67
0
Somewhere on Earth
Code:
#include <stdio.h>
#include <readpassphrase.h>

int main()
{
	const int passwordLength = 20;
	char password[passwordLength];
	readpassphrase("Enter the password: ", password, passwordLength, 0);
	printf("You entered: %s\n", password);
	
	return 0;
}
I tried you code and all it tells you is what you typed in. I'm trying to find out a way to replace the characters you type in with asterisks! Can anyone help w/ that problem?
 

unknown.exe

macrumors member
Original poster
Sep 22, 2007
67
0
Somewhere on Earth
What's with the hysterics?

Do your own homework.

*sigh*................................................ can anyone give me a straight answer because i've been looking all over the net and in text-books and I can't find an answer...... just please give me something?
 

xUKHCx

Administrator emeritus
Jan 15, 2006
12,583
9
The Kop
Well it still worked w/ C++............... BUT FOR THE LOVE OF GOD CAN ANYONE ANSWER MY QUESTION!?!?!?!?!?!?!?!?!?! EVERYONE HAS BEEN BEATING AROUND THE BUSH FOR HALF THE POSTS!!!:D

If you want people to answer your question don't edit your post after someone has responded because they may not see it, and it sort of makes them look foolish and don't demand an answer.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.