Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

how make password...?

I need to know something..
How to make a C program that will let user type any words but when they are typing they can not see what they are typing they only see asterisk (*) for example: they will type hello the output in the screen is ***** like that like the principle in passwords.


Thanks for the someone that will help me :)
«1

Comments

  • MT2002MT2002 Posts: 1,444Member
    : I need to know something..
    : How to make a C program that will let user type any words but when they are typing they can not see what they are typing they only see asterisk (*) for example: they will type hello the output in the screen is ***** like that like the principle in passwords.
    :
    :
    : Thanks for the someone that will help me :)
    :
    [blue]
    You are referring to recieving input without echo (ie, getting input without displaying it). This will allow your program to output another character (or not) in its place (as the *)

    There is no standard way to do this. With borland compilers, you can use [b]getche[/b]. With MSVC++ you will need to use the Win32 API Console routines.

    What compiler are you using?[/blue]
  • richardbautistrichardbautist Posts: 21Member
    tnx for replying by the way i am using TURBO C... and what i am saying is that when somebody is typing he can not see the letters but only asterisk (*)... when he type a wrong word it will display wrong code but if its correct the program will say "Its right"
    pls help me
  • MT2002MT2002 Posts: 1,444Member
    [b][red]This message was edited by MT2002 at 2007-2-1 22:53:35[/red][/b][hr]
    : tnx for replying by the way i am using TURBO C... and what i am saying is that when somebody is typing he can not see the letters but only asterisk (*)... when he type a wrong word it will display wrong code but if its correct the program will say "Its right"
    : pls help me
    :
    [blue]
    You can use [b]getche()[/b] in a loop..
    [/blue][code]
    char pass[10];
    memset (pass,0,10); //clear string

    for (int i=0; i<10; i++) {

    char c=getche();
    if (c=='
    ') //break if newline
    break;
    pass[i]=c;
    printf ("*");
    }
    [/code][blue]
    I dont have TurboC atm, but this should work just fine. This loop will break if either a)user enters newline char, or more then 10 chars entered.

    Please note that getche() is Borland specific.

    Also, you can use the [b]strcmp()[/b] routine from [b]string.h[/b] to compare if two strings match.

    Also, This code is C NOT C++. (I know TurboC 2.1 doesnt support C++)
    If you need a C++ version, let us know.

    Hope this helps;[/blue]




  • richardbautistrichardbautist Posts: 21Member
    Thanks for your replies and im sorry that i disturbed you too much... :(
    Because im still a student and our subject is only C Language and my teacher required us to use only Turbo C program... he requires us to do a program (password.c)... hope u can help me again TNX a LOT... GOD BLESS YOUR LIFE !!!

  • MT2002MT2002 Posts: 1,444Member
    : Thanks for your replies and im sorry that i disturbed you too much... :(
    [blue]
    No worry--Its fun. Gives me something to do :-)
    [/blue]
    : Because im still a student and our subject is only C Language and my teacher required us to use only Turbo C program... he requires us to do a program (password.c)... hope u can help me again TNX a LOT... GOD BLESS YOUR LIFE !!!
    :
    [blue]
    getche() is the way to go...[/blue][code]
    #include
    #include
    #include

    #define PASS_SIZE 10

    int main (int argc, char** argv) {

    char cCur=0;
    char Password[PASS_SIZE+1] = "Password"; /*actual password*/
    int i=0;

    char strPass[PASS_SIZE+1];

    /* null out our string */
    memset (strPass, 0, PASS_SIZE);

    /* get password */
    for (i=0; i<PASS_SIZE; i++) {

    char c=getche ();
    if (c=='
    ' || c=='
    ') /* watch for NL/CR feed */
    break;
    strPass[i]=c;
    putch ("*");
    }
    strPass[i+1]=''; /* add null terminator */

    /* compare passwords */
    if (strcmp (strPass, Password)==0) {

    /* passwords match */
    }

    return 0;
    }
    [/code][blue]
    Not compiled nor tested. This should work however. Either way, the concept is still the same.[/blue]
  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [blue]You need the pair getch()/putch('*') to do this.[/blue]
  • MT2002MT2002 Posts: 1,444Member
    : [blue]You need the pair getch()/putch('*') to do this.[/blue]
    :
    [blue]
    You are correct--my bad. Havnt worked with DOS is awhile :-)[/blue]
  • richardbautistrichardbautist Posts: 21Member

    how to pair that what shud i do? write?
  • MT2002MT2002 Posts: 1,444Member
    :
    : how to pair that what shud i do? write?
    :
    [blue]Try this...[/blue][code]
    #include
    #include

    #define PASS_MAX 10

    int main () {

    char pass[PASS_MAX+1];
    int i=0;

    memset (pass,0,PASS_MAX+1);
    clrscr ();

    for (i=0; i<PASS_MAX; i++) {

    char c=getch();
    if (c=='
    ' || c=='
    ')
    break;
    pass[i]=c;
    putch ('*');
    }

    if (! strcmp (pass, "Password"))
    printf ("
    Welcome");

    getch();
    return 0;
    }
    [/code][blue]
    If the user types in "Password" a greeting message is displayed.

    After the user types the password, the program waits for any key to teminate.
    [/blue]
  • richardbautistrichardbautist Posts: 21Member
    Thanks for the codes you gave me... it worked with TURBO C 2.01 !!!
    that's all for now...
    maybe i can ask you more difficult again next time...

    gudnyt

    :)

    just help me with my other posts okay??

    thanks :)
«1
Sign In or Register to comment.