Hiding input password

This is a discussion on Hiding input password within the C++ Programming forums, part of the General Programming Boards category; Im trying to make an login menu in Visual studio 6.0. I want the password to be typed in as ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    2

    Unhappy Hiding input password

    Im trying to make an login menu in Visual studio 6.0. I want the password to be typed in as '*' , so you cant se the real password on the screen. Im building a MS-DOS interface. Here is the code we allready have tried and it didn't work..

    #include <iostream.h>
    #include <conio.h>

    main ()
    {
    int c=0;
    char buffer[20];
    char a;
    char n[11];

    cout << "Name: ";
    cin >> n;
    cout << "Password: ";

    while(a != '\n')
    {
    a=getch();
    buffer[c]=a;
    cout<<"*";
    c++;
    }

    cout<<buffer;
    return 0;
    }

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    You can't use old type I/O, (getch), and stream I/O, (cout, cin), on the same channel at the same time without problems. Use one or the other.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    It is always better to continue these threads on the board rather than take it to e-mail. First, I am not in the office that often, you were lucky, second, nobody else learns anything!

    Code:
    #include <stdio.h>
    #include <conio.h> 
    
    main () 
    { 
      int c=0; 
      char buffer[20]; 
      char a; 
      char n[11];
      bool Continue = 1;
    
      printf("Name: "); 
      scanf("%s",&n); 
      printf("Password: "); 
    
      while (Continue) 
      { 
        a=getch();
        if (a == 13)
        {
          Continue = 0;
          buffer[c] = 0;
        }
        else
        { 
          buffer[c]=a; 
          printf("*"); 
          c++;
        } 
      };
      printf("\n%s\n",buffer);
     
      return 0; 
    }
    This is a bit nasty as I didn't have a lot of time, but basically works with VC6.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help with C program writing
    By The_PC_Gamer in forum C Programming
    Replies: 9
    Last Post: 02-12-2008, 08:12 PM
  2. large program code ,please help
    By Ash1981 in forum C Programming
    Replies: 14
    Last Post: 01-30-2006, 05:16 AM
  3. Custom Made Safe Input Function
    By Beast() in forum C Programming
    Replies: 6
    Last Post: 08-21-2004, 10:19 PM
  4. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 12:50 PM
  5. Hiding Input
    By bigbrainstorms in forum C++ Programming
    Replies: 4
    Last Post: 03-06-2003, 03:24 AM

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