Thread: How to mask password to asterisk, and correct password displays valid

  1. #1
    Registered User
    Join Date
    Apr 2020
    Posts
    8

    How to mask password to asterisk, and correct password displays valid

    Hi, the main problem is getting stuck at the if part. Idk how to make the statement or the transition it from there.
    All advice is appreciated and thank you in advance.

    Code:
    #include <stdio.h> 
    #include <conio.h> 
    #include <string.h>
    
    
    int main ()
    {
        char username[20];
        char password[20];
        char ch;
         int i;
    
    
        printf("\nEnter your username: ");
        scanf("%s",username);
     
     
        printf("*********************************\n");
        printf("Enter your password:\n");
        scanf("%s",password);
        for(i=0;i<8;i++)
         {
          ch = getch();
          password[i] = ch;
          ch = '*' ;
          printf("%c",ch);
         }
     
        password[i] = ' ';
        
         if( strcmp ( username,"xxX_slayer69_Xxx" ) == 0 && strcmp ( password,"password" ) == 0 )
        {
            
            printf("VALID\n");
        }
        else 
        {  
        puts("INVALID\n");   
        return 0;
        }
    }#include <stdio.h> 
    #include <conio.h> 
    #include <string.h>
    
    
    int main ()
    {
        char username[20];
        char password[20];
        char ch;
         int i;
    
    
        printf("\nEnter your username: ");
        scanf("%s",username);
     
     
        printf("*********************************\n");
        printf("Enter your password:\n");
        scanf("%s",password);
        for(i=0;i<8;i++)
         {
          ch = getch();
          password[i] = ch;
          ch = '*' ;
          printf("%c",ch);
         }
     
        password[i] = ' ';
        
         if( strcmp ( username,"xxX_slayer69_Xxx" ) == 0 && strcmp ( password,"unliveme" ) == 0 )
        {
            
            printf("VALID\n");
        }
        else 
        {  
        puts("INVALID\n");   
        return 0;
        }
    }

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,875
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Apr 2020
    Posts
    8
    Quote Originally Posted by Click_here View Post
    Hi thanks for the input, i had a hard time breaking it down but thanks to the wording of the post i googled using that same wording and found this thread: Any method to mask the password that the user entered?

    Code:
    #include <stdio.h>#include <conio.h>
     
    int main()
    {
        char password[100];
        char username[20];
    	int i=0;
     	
     	printf("\nEnter your username: ");
        scanf("%s",username);
     
     
        printf("*********************************\n");
        printf("Enter your password:\n");
        do
        {
            password[i]=getch();
            printf("*");
            i++;
        }
        while(password[i-1]!='\r');
        password[i-1]='\0';
        
        if( strcmp ( username,"xxX_slayer69_Xxx" ) == 0 && strcmp ( password,"password" ) == 0 )
        {
            
            printf("\nVALID\n");
        }
        else 
    	{  
    	puts("\nINVALID\n");   
    	return 0;
        }
    }
    So yeah it works, thanks so much btw.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making password into asterisk help.......!
    By danial92 in forum C Programming
    Replies: 7
    Last Post: 08-30-2011, 04:25 PM
  2. Mask Password
    By ethanhayon in forum C Programming
    Replies: 1
    Last Post: 07-06-2011, 03:36 PM
  3. Asterisk Password
    By adnilsah017 in forum C Programming
    Replies: 4
    Last Post: 05-29-2011, 12:16 PM
  4. C++ Password mask
    By nick753 in forum C++ Programming
    Replies: 2
    Last Post: 09-12-2010, 01:05 AM
  5. Password Asterisk
    By $l4xklynx in forum C Programming
    Replies: 5
    Last Post: 10-30-2008, 03:08 PM

Tags for this Thread