Thread: Changing characters to ***

  1. #16
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    801
    and i'v made changes to the code, I'v removed all the junk and the 'username' part....and added coments!!!!!!!
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: [email protected] []*[]

  2. #17

  3. #18
    Unregistered
    Guest
    to add the use of backspace, replace this with the inputcode() function:

    Code:
    //refer to the link from the previous post
    ...
    void inputcode(char*&x)
    {
     cout<<flush;
     for(i=0;i<8;i++)
     {
      x[i]=char(getch());
      cout<<"*"<<flush;
      if(x[i]==char(13) || x[i]=='\t' || x[i]=='\r' || x[i]==' '){break;}
      else if(x[i]=='\b'){cout<<"\b";i--;}
     }
     fillcode(++i); //fillcode(i+1);
    }
    ...
    - toaster

  4. #19
    Registered User
    Join Date
    Oct 2001
    Posts
    16

    compiler

    I was wondering if you could please tell me the compiler that this code will work in because it does not want to seem to want to work in mine

    Thanks

    sp00k
    Last edited by sp00k; 05-19-2002 at 01:17 AM.

  5. #20
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Unregistered
    to add the use of backspace, replace this with the inputcode() function:

    Code:
    //refer to the link from the previous post
    ...
    void inputcode(char*&x)
    {
     cout<<flush;
     for(i=0;i<8;i++)
     {
      x[i]=char(getch());
      cout<<"*"<<flush;
      if(x[i]==char(13) || x[i]=='\t' || x[i]=='\r' || x[i]==' '){break;}
      else if(x[i]=='\b'){cout<<"\b";i--;}
     }
     fillcode(++i); //fillcode(i+1);
    }
    ...
    - toaster
    This is C++, and we're on a C board!

    Now, you could all take note of Prelude's code which does what you want and is easily adapted to store the input for later use, or you could all waste more time talking about it. It's up to you
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #21
    Unregistered
    Guest
    hi you can get this one:
    PHP Code:
    #include "stdio.h"
     #include "conio.h"
     #include "string.h"
     #include "stdlib.h"

     #define Back 8


     
    int getcode(void)
     {
        
    int t;
        
    getch();
        
        if ( ( 
    == ) || ( == 0xE0 ) )
            
    getch() ;

        return 
    t;
     }
    //---------------------------------------
    //---------------------------------------
     
    char *getpass(void)
     { 

        
    int ic;
        
    char *pass ;

        
    pass = (char*)malloc(sizeof(char));

        
    i=0;
        
    c=0;

            
    getcode();

                while( (
    != 13) && (Back) ) 
                { 
                    if( 
    == Back )
                    {
                        if( 
    == )
                            ;    
    // Do Nothing....
                        
    else
                        {
                            
    i-- ;
                            
    printf("\b \b");    //Back than print blank ' ' then back...
                        
    }//else
                    
    }
                    else if( ((
    c>=65) && (c<=90)) || (( c>=97 ) && ( c<=122 )) || (( c>=48 ) && ( c<=57 )))
                    {    
    // make sure that the input is not anything but A-Z || a-z || 0-9 ...
                        
    pass[i] = ;
                        
    i++ ;
                        
    printf("*");
                    }
    //else if
                        
                    
    c=getcode();
                }
    //while 
        
                
    if( i<pass[i] = '\0';
                
    // give the string NULL if not full (less than 8) ...

        
    return pass;
     }
    // getpass
    //----------------------------------------
    //----------------------------------------

     
    int main()
     {
        
    char *str1, *str2 "asd123" ;
        
    str1 NULL ;

        
    printf("\nHi Please Enter The Pass Word: ");
        
    str1 getpass(); 

        if( 
    strcmp(str1str2) == )
            
    printf("\nHi there are EQUAL ...");
        else
            
    printf("\nSorry try agen");

        return 
    ;
     } 


    - talal*c

  7. #22
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >hi you can get this one:
    Exactly, why use 9 lines of code when you can write 83. That's much easier for the newbies to understand.
    [/sarcasm]
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #23
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Was Prelude's code that complex?
    The world is waiting. I must leave you now.

  9. #24
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    801
    yes.......yes it was
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: [email protected] []*[]

  10. #25
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    First let me ask you, How was it so complex?
    Second, do you still need help?
    The world is waiting. I must leave you now.

  11. #26
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Commander
    yes.......yes it was
    OK, which part would you like help with?
    Code:
    /* Prelude's original 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;
    }
    Now, just to clarify, this code doesn't perform a password comparison. It mearly shows you how to best obtain the password from the user. To expand it to store the password, you'd need to store each ch in an array. You can also cater for backspace by simply removing the last character from the array when a backspace is read. Something like this:
    Code:
    #include <stdio.h>	 
    #include <conio.h>
    #include <ctype.h>
    
    #define PASSLEN 10
    
    int main(void)
    {
    	int ch, i;
    	char password[PASSLEN+1];
    			
    	printf("Enter your password: ");
    	
    	i = 0;
    	while ((ch = getch()) != '\r' && i < PASSLEN)
    	{
    		if (ch == '\b') 
    		{	/* Handle backspace */
    			if (i > 0) {i--; printf("\b \b");}
    			password[i] = '\0';
    		}
    		else if (isalnum(ch))
    			{	/* Only characters and numbers considered to be part of the password */
    				password[i] = ch;
    				putchar('*');
    				i++;
    			}
    	}
    	
    	password[i] = '\0';
    	printf("\nThank you, you entered: %s\n", password);
    	return (0);
    }
    Alternatively, you could check each letter of the password as you get it from the user (instead of storing it in an array).

    Also, doing this kind of thing:
    >char master_password[] = "superdupervisor";
    is not recommended. You only need to hex dump the exe and someone will find out the password. You should store it as encrypted text.
    Last edited by Hammer; 05-20-2002 at 03:32 AM.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

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, 10: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, 03:45 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Replies: 5
    Last Post: 12-22-2004, 05:46 PM