Jump to content

Replace input with a chosen character

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
hbk

hbk

    Learning Programmer

  • Members
  • PipPipPip
  • 71 posts
i want to block the password from appearing to the user when he enters it.

I have the code below but its not terminating.

int main()

{

    

    char username[9],username1[9];   

    char password [5],pass[5];

    int y=1,i=0;

    

    strcpy(username1,"udental");

    strcpy(password,"1987");

    

    display();

    

    system("color 2");

    do

    {

                 

                  

                  printf("\n\n\n\n\n\n\t\t\tPLEASE ENTER YOUR USERNAME:");

                  gets(username);

                  

                  printf("\n\n\n\n\n\t\t\tPLEASE ENTER YOUR PASSWORD:");

                  gets(pass);

                  

                   while((pass[i]=getch())!='\r')


                               {

                                       putchar("*");


                                       i++;


                                }

                  

                  printf("\n\n\t\t\t    PRESS ENTER TO CONTINUE");

                  getch();

                  

                           

                                                              

                           if (strcmp(username,username1)==0 &&  strcmp(password,pass) == 0)

                           

                            {

                                Sleep(1000);  

                                system("cls");                                

                                vital();

                                Sleep(1000);  

                                system("cls");

                                menu();

                                Sleep(1200); 

                                system("cls");

                                break;                                                                                                                                                

                               

                             } 

                               

                           else 

                           

                            {

                                printf("\n\n\t\t\t YOU HAVE MADE AN INVALID INPUT");

                                printf("\n\n\t\t\t      PLEASE TRY AGAIN\n\n"); 

                                Sleep (1000);

                                system("cls");

                            }                             

                  

                  

                  y++;

                  

     }while(y<4); 

                 

    system("cls");

    printf("\n\n\t\t\t  YOU HAVE BEEN LOCKED FROM THE SYSTEM");

    printf("\n\n\t\t\t\t          GOODBYE");

    

    

    

    getch();

    return 0;

}



#2
abdul.gafur

abdul.gafur

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
with gets, input form user will be shown on screen. maybe you can use getch().
just a drop of dew in the morning
( loop while (= x true) do (x) )

#3
thechef

thechef

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
It looks like you need to make it so cin doesn't echo the characters in it's buffer. You will have to use SetConsoleMode() to turn the echo off. I think this link might help you out: Unbuffered input - C++ Forums