PDA

View Full Version : Xcode C++ help! Replacing input with *'s(password protecting)




unknown.exe
Dec 3, 2007, 06:04 PM
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:



mduser63
Dec 3, 2007, 07:44 PM
Don't use goto statements. Other than that I have no advice (too lazy to think at all right now).

Luis
Dec 3, 2007, 07:48 PM
if (password == 2090407)


Be sure to change the password before you release the app ;)

yeroen
Dec 3, 2007, 08:10 PM
just look at the source for /usr/bin/login and see what it does

yeroen
Dec 3, 2007, 08:21 PM
this is what you want: the function readpassphrase from <readpassphrase.h>

just do a man on readpassphrase for more info

unknown.exe
Dec 3, 2007, 08:45 PM
Uuuummmm, the readpassphrase sounds promising, but can anyone give me a real example of how to do wut i'm tryin 2 do?

unknown.exe
Dec 3, 2007, 09:04 PM
Really it seems a simple matter of telling the compiler to replace all input w/ a character... but how do you do that?

kainjow
Dec 3, 2007, 09:15 PM
Uuuummmm, the readpassphrase sounds promising, but can anyone give me a real example of how to do wut i'm tryin 2 do?

#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
Dec 3, 2007, 09:24 PM
#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?

kainjow
Dec 3, 2007, 09:27 PM
ok ill give this code a try (PS: You forgot iostream):apple:

I wrote it in C, not C++ ;)

unknown.exe
Dec 3, 2007, 09:33 PM
I wrote it in C, not C++ ;)

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

yeroen
Dec 3, 2007, 09:35 PM
What's with the hysterics?

Do your own twatting homework.

You're lucky anyone answered you in the first place.

unknown.exe
Dec 3, 2007, 09:36 PM
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
Dec 3, 2007, 09:37 PM
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.

unknown.exe
Dec 3, 2007, 09:39 PM
I didnt realise someone had responded until it wus too late... but does anyone have any help 4 me?

yeroen
Dec 3, 2007, 10:28 PM
http://www.steve.org.uk/Reference/Unix/faq_4.html