Changing characters to ***

This is a discussion on Changing characters to *** within the C Programming forums, part of the General Programming Boards category; Hello I was wondering if anyone could help me? I am writing a program in turbo c for dos and ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    16

    Question Changing characters to ***

    Hello

    I was wondering if anyone could help me?

    I am writing a program in turbo c for dos and i am trying to make a password module.
    So when the user enters there password the password comes up on the screen in ******* instead of characters.

    If anyone could help me that would be great
    Thankyou

    Spook

  2. #2
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    804
    Code:
    void password(void){
    
    
    
    char name2[210], pass[210];
    int n=0, p=0;
    
    textcolor(YELLOW);
    highvideo();
       clrscr();clrscr();
    
    for(;;){
    textcolor(YELLOW);
    clrscr();
    printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");printf("*IMPORTANT NOTE*  : <backspace> is not allowed.  If you press <backspace>, while\n");
    printf("typing the User Name or Password, they will be considerd incorrect.\n");
    cprintf("\n");
    cprintf("\n");
        cprintf("");
            cprintf("  ENTER LOGIN NAME >> ");
    
    cprintf("\n\n");
            cprintf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
            cprintf("ENTER PASSWORD >> ");delay();delay();
    
    gotoxy(23,8);
    cscanf("%s", name2);
    if((!strcmp(name2, "q"))==1){gotoxy(1,8);  cprintf("%c", 258); n=1;}
    else {gotoxy(1,8); cprintf("X");}
    
    gotoxy(21,10);
    
    
    
    getch();
    
    
    
    for(int i=0;;i++){
    pass[i]=getch();
    
    if(pass[i]=='\r'){break;}
    if(pass[i]=='\b'){printf("\b"); i=i-2; continue;}
    
    cprintf("%c", 177);
    }
    
    
    
    
    
    
    if((pass[0]=='w') && (pass[1]=='o') && (pass[2]=='r') && (pass[3]=='d'))
    
    
    {gotoxy(1,10);   cprintf("%c", 258); p=1;}
    else {gotoxy(1,10); cprintf("X");}
    gotoxy(1,12);
    textcolor(RED);
    if((p==0) || (n==0)){cprintf("\a\a   -The correct login name and password must be provided to enter the database.    -If you have pressed [backspace], please try to avoid pressing it next time."); pause(); clrscr();}
    else {break;}
    }
    
    
    }
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: commander_android@hotmail.com []*[]

  3. #3
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    804
    I wrote this code a long time ago. So I never bothered to put comments in it because I thought i was the only one who will be using it. There are a few bugs in the program...like you can't press [backspace] in the password section.
    2 > for instance, if you want ur pass to be 'word', you'll have to define it like this
    Code:
    if((pass[0]=='w') && (pass[1]=='o') && (pass[2]=='r') && (pass[3]=='d'))

    more over, password is a function, you can call it anytime you want in a program. this function doesn't return anything, it just dosen't exit the loop until the correct passwrod has been entered...


    hope this helped....
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: commander_android@hotmail.com []*[]

  4. #4
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    804
    by the way, this program doesn't put *, in place of the chars, it puts a [] (box looking thing)...then again, I don't think it really makes a difference...
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: commander_android@hotmail.com []*[]

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    16

    Thanks

    Hey commander,

    I am new at this and well i dont really understand what this line of text does??

    Where exactly do you put it in the program

    eg

    Code:
    pass[5];
    for(;;)
    {
    scanf("%s", &pass);
    if((pass[0]=='w') && (pass[1]=='o') && (pass[2]=='r') && (pass[3]=='d'))
      break();
    }
    is this right or not

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    16

    commander

    The first big piece of text well that is a mystery to me i was wondering if you could explain it

    Thanks spook

  7. #7
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > for instance, if you want ur pass to be 'word', you'll have to define it like this
    The world is waiting. I must leave you now.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    void password(void){
    <snip lots of wasteful code>
    }
    How about breaking it down to bare bones so that it's easier to understand?
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main ( void )
    {
      int ch;
      printf ( "Enter your password: " );
      while ( ( ch = getch() ) != '\r' )
        putchar ( '*' );
      printf ( "\nThank you\n" );
      return 0;
    }
    -Prelude
    My best code is written with the delete key.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    16

    Thanks

    Thanks shadow what i mean is

    how do you put the box there in the passord field in stead of characters

    > by the way, this program doesn't put *, in place of the chars, it puts a [] (box looking thing)...

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    16
    where exactly do you enter your password

    How about breaking it down to bare bones so that it's easier to understand?
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main ( void )
    {
      int ch;
      printf ( "Enter your password: " );
      while ( ( ch = getch() ) != '\r' )
        putchar ( '*' );
      printf ( "\nThank you\n" );
      return 0;
    }

  11. #11
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > where exactly do you enter your password
    After you compile the program and it asks you to do so
    The world is waiting. I must leave you now.

  12. #12
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    What's '\r' ?

  13. #13
    Registered User
    Join Date
    Oct 2001
    Posts
    16

    it return

    /r = enter

  14. #14
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    804
    PHP Code:

    void password 
    (void);   //defining the function

    //**********************************************


    main(){
    password();}


    //***********************************************



    void password(void){



    char pass[210]="";
    int p=0;


    for(;;){            
    //main loop; dosen't break till the pass matches
    clrscr();
    cprintf("  ENTER PASSWORD >> ");



    for(
    int i=0;;i++){     //loop where the user starts pression keys
    pass[i]=getch();       //scans the keys
    if(pass[i]=='\r'){break;}   //if user presses ENTER, the loop breaks
    if(pass[i]=='\b'){printf("\b"); i=i-2printf(" \b"); continue;}   // \b [BACKSPACE] thing does work!!!!
    cprintf("*");     //prints a * instead of the actual letters
    }                 //end of loop



    if((pass[0]=='w') && (pass[1]=='o') && (pass[2]=='r') && (pass[3]=='d'))    //checks to see if the entered password is "word"
    {gotoxy(1,1);   cprintf("%c"258); p=1;     //if it is, it prints a happy face in the begining of the password line
    gotoxy(1,2);
    printf("you have typed the right password"); getch();  //and types this afterwards
     
    }

    else {
    gotoxy(1,1); cprintf("X");}  //if the password is not "word" it prints an X in the begining of the password line
    gotoxy(1,2);
    if(
    p==0){cprintf("\n\n-The correct login name and password must be provided to enter the database.\
    -If you have pressed [backspace], please try to avoid pressing it next time.\n\n"
    ); system("pause");  clrscr();}
    //it prints some craps after this

    }  //end of for loop




    }
                        
    //end of function


    //************************************************** 
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: commander_android@hotmail.com []*[]

  15. #15
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    804
    I've made some changes with the [backspace] thing...it's working...but it sometimes get's bustedwhen the string entered is too long
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: commander_android@hotmail.com []*[]

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 11:39 PM
  2. Changing characters in a file using a buffer
    By papagaio in forum C Programming
    Replies: 3
    Last Post: 12-23-2008, 10:32 AM
  3. Replies: 10
    Last Post: 07-10-2008, 04:45 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM
  5. Replies: 5
    Last Post: 12-22-2004, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21