Hide password in text box

Hello,

I have two text boxes on screen, one a username and one a password. I would
like to have the password text replaced with stars instead of displaying the
actual characters.

I have seen the example from the helpfile and it appears as though it
creates the widgets at runtime. I would just like a few lines of code to do
the substitution and to keep the text entered.

I would appreciate any assistance with this.

Thanks

Adam

ps. PtPassword is of no use to me as I have two textboxes on a pre-made
screen. I do not want to have a separate popup screen.

i have few lines of code that might help, it basically counts the length of
the current password entered, then print that number of stars instead.
attach it to text_changed_cb;
int PrintAstricks_CB( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )

{ char localstr[50];

int i, j;

PtArg_t args[1];

String str1;

str1 = getchararray(ABW_PtText_Password, Pt_ARG_TEXT_STRING);

sprintf(localstr, “”);

j = str1.length();

if(j > 49) j = 49;

for(i=0; i < j; i++) strcat(localstr,"*");

PtSetArg(&args[0], Pt_ARG_TEXT_STRING, localstr, NULL);

PtSetResources(ABW_PtText_AsterickPassword, 1, args);

return( Pt_CONTINUE );

}

“Adam Williams” <adam_williams@hotmail.com> wrote in message
news:citsjm$o85$1@inn.qnx.com

Hello,

I have two text boxes on screen, one a username and one a password. I
would
like to have the password text replaced with stars instead of displaying
the
actual characters.

I have seen the example from the helpfile and it appears as though it
creates the widgets at runtime. I would just like a few lines of code to
do
the substitution and to keep the text entered.

I would appreciate any assistance with this.

Thanks

Adam

ps. PtPassword is of no use to me as I have two textboxes on a pre-made
screen. I do not want to have a separate popup screen.

Here is a technique that I have used in the past:

  • Make two identical textboxes, one on top of the other.
  • The back one is the “real” password.
  • The front one will only show asterisks.
  • Attach the following modify_verify callback to the front (“fake”)
    textbox.

int
cfg_pw_modify_verify( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t *cbinfo )

{
PtTextCallback_t *cbs = (PtTextCallback_t *) cbinfo->cbdata;
PtArg_t args[1];
int len;
CFG *cfg;

/* eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

/* Edit the REAL password widget */

cfg = get_user_data( widget );
PtSetArg( &args[0], Pt_ARG_TEXT_SUBSTRING, cbs, 0 );
PtSetResources( cfg->real_passwd_wgt, 1, args );

for( len = 0; len < cbs->length; len++ )
cbs->text[len] = ‘*’;

return( Pt_CONTINUE );

}

In this case, cfg->real_passwd_wgt is a PtWidget_t* to the “real”
password textbox. I had explicitly stored it in the “fake” password
textbox’s user_data pointer. Odds are you can simply use the ABW_*
manifest provided by PhAB.


James

Adam Williams wrote:

Hello,

I have two text boxes on screen, one a username and one a password. I would
like to have the password text replaced with stars instead of displaying the
actual characters.

I have seen the example from the helpfile and it appears as though it
creates the widgets at runtime. I would just like a few lines of code to do
the substitution and to keep the text entered.

I would appreciate any assistance with this.

Thanks

Adam

ps. PtPassword is of no use to me as I have two textboxes on a pre-made
screen. I do not want to have a separate popup screen.