Xcode C++ help! Replacing input with *'s(password protecting)

Discussion in 'Mac Programming' started by unknown.exe, Dec 3, 2007.

  1. unknown.exe macrumors member

    unknown.exe

    Joined:
    Sep 22, 2007
    Location:
    Somewhere on Earth
    #1
    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:
     
  2. mduser63 macrumors 68040

    mduser63

    Joined:
    Nov 9, 2004
    Location:
    Salt Lake City, UT
    #2
    Don't use goto statements. Other than that I have no advice (too lazy to think at all right now).
     
  3. Luis macrumors 65816

    Luis

    Joined:
    Jul 19, 2006
    Location:
    Costa Rica
    #3
    Be sure to change the password before you release the app ;)
     
  4. yeroen macrumors 6502a

    yeroen

    Joined:
    Mar 8, 2007
    Location:
    Cambridge, MA
    #4
    just look at the source for /usr/bin/login and see what it does
     
  5. yeroen macrumors 6502a

    yeroen

    Joined:
    Mar 8, 2007
    Location:
    Cambridge, MA
    #5
    this is what you want: the function readpassphrase from <readpassphrase.h>

    just do a man on readpassphrase for more info
     
  6. unknown.exe thread starter macrumors member

    unknown.exe

    Joined:
    Sep 22, 2007
    Location:
    Somewhere on Earth
    #6
    Uuuummmm, the readpassphrase sounds promising, but can anyone give me a real example of how to do wut i'm tryin 2 do?
     
  7. unknown.exe thread starter macrumors member

    unknown.exe

    Joined:
    Sep 22, 2007
    Location:
    Somewhere on Earth
    #7
    Really it seems a simple matter of telling the compiler to replace all input w/ a character... but how do you do that?
     
  8. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    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;
    }
     
  9. unknown.exe thread starter macrumors member

    unknown.exe

    Joined:
    Sep 22, 2007
    Location:
    Somewhere on Earth
    #9
    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?
     
  10. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #10
    I wrote it in C, not C++ ;)
     
  11. unknown.exe thread starter macrumors member

    unknown.exe

    Joined:
    Sep 22, 2007
    Location:
    Somewhere on Earth
    #11
    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
     
  12. yeroen macrumors 6502a

    yeroen

    Joined:
    Mar 8, 2007
    Location:
    Cambridge, MA
    #12
    What's with the hysterics?

    Do your own twatting homework.

    You're lucky anyone answered you in the first place.
     
  13. unknown.exe thread starter macrumors member

    unknown.exe

    Joined:
    Sep 22, 2007
    Location:
    Somewhere on Earth
    #13
    *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?
     
  14. xUKHCx Administrator emeritus

    xUKHCx

    Joined:
    Jan 15, 2006
    Location:
    The Kop
    #14
    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.
     
  15. unknown.exe thread starter macrumors member

    unknown.exe

    Joined:
    Sep 22, 2007
    Location:
    Somewhere on Earth
    #15
    I didnt realise someone had responded until it wus too late... but does anyone have any help 4 me?
     

Share This Page