Thread: Masking Text

  1. #1
    Unregistered
    Guest

    Post Masking Text

    How do I mask TEXT for example...

    The programn askes you input password
    then you put in your password but how do you mask it so you cant acually see the letters?

  2. #2
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    You need an input method that does not echo to the screen. Then you could just replace the input (character by character) with another character such as an asterisk, or not at all. Do a search this has been discussed many times on these boards.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    you could do something like this:

    Code:
    #include <conio.h>
    #include <iostream.h>
    
    //..
    
    char a;
    char password[255];
    
    while((int)a != 27)
    {
        a = getch();
    
        if((int)a != 27)
        {
            cout << "*";
            strcat(password, a);
        }
    }
    im not exactly sure, and i cant compile it ATM, but u can try it
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  4. #4
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Is 27 the ascii code for the carriage return, so the loop will condition will become false as soon as the user hits enter?
    Be a leader and not a follower.

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    79
    Here is a function I think you might be able to use. It is a function to input a password with a limiting length of 25 characters...

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

    void getpassword(char *string)
    {
    for(int counter=0; counter<maxlength; counter++) //maxlength is the maximum size of the string. This loop is for the purpose of making all elements of the string null.
    string[counter]=0;
    int *len=new int; *len=0; char c=0;
    while(c!=13)
    {
    c=char(getch());
    if(*len<=24)
    {
    if(*len!=0 && c=='\b')
    {
    string[*len-1]=0; gotoxy(wherex()-1,wherey()); clreol(); (*len)--;
    }
    if(*len!=0 && c=='\b' && wherex()==1)
    {
    string[*len-1]=0; gotoxy(80,wherey()-1); (*len)--;
    }
    if(c!='\b' && c!=13)
    {
    cout<<"*";
    string[*len]=c; (*len)++;
    }
    if(c==13)
    {
    cout<<endl;
    }
    }
    if(*len>=25 && c=='\b')
    {
    string[*len-1]=0; gotoxy(wherex()-1,wherey()); clreol(); (*len)--;
    }
    }
    delete len;
    }

    Compiler:Borland C++ 5.0
    Last edited by sundeeptuteja; 07-03-2002 at 05:07 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble drawing text xlib.
    By Qui in forum Linux Programming
    Replies: 1
    Last Post: 05-10-2006, 12:07 PM
  2. Appending text to an edit control
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 08-13-2004, 09:52 PM
  3. Text positioning and Text scrolling
    By RealityFusion in forum C++ Programming
    Replies: 3
    Last Post: 08-13-2004, 12:35 AM
  4. Scrolling The Text
    By GaPe in forum C Programming
    Replies: 3
    Last Post: 07-14-2002, 04:33 PM
  5. Replies: 1
    Last Post: 07-13-2002, 05:45 PM