Path: utzoo!attcan!uunet!mailrus!umich!caen!etsu!cmi.com!dave From: dave@cmi.com (David Halonen) Newsgroups: comp.sys.mac.programmer Subject: Re: Password Dialogs--what is the best way to do them? Message-ID: <3142@etsu.CMI.COM> Date: 11 Jul 90 16:44:21 GMT Sender: news@etsu.CMI.COM Organization: Center for Machine Intelligence, EDS Corp. Lines: 37 References:<36805@shemp.CS.UCLA.EDU> <3663@adobe.UUCP> A very simple solution: Get the text string, rip of the last character typed in, store it, replace with a character of your choice, replace the original string with modified, wait for next char. Sample code follows: do { len = *displayStr; ModalDialog( nil, &itemHit); GetIText( itemHdl, &displayStr ); newLen = *displayStr; if( newLen != len ) { if( newLen > len ) {/*user added a char*/ sprintf( (char *) answer, "%s%c", answer, displayStr[ newLen ] ); displayStr[ newLen ] = (char) 0xA5;/*convert char to '%'*/ } else {/*user deleted a char*/ *displayStr = newLen; *(answer + len - 1) = (char) 0x00;/*adjust end of 'C' string*/ } SetIText( itemHdl, displayStr ); } } while ( (itemHit != okButton) & (itemHit != cancelButton) ); if ( itemHit == okButton ) { CtoPstr( (char *) answer );/*sprintf turns it into a C string*/ if( EqualString( &answer, paPassword, false, false ) ) valid = true; } Ugly, but it works. David Halonen, Center for Machine Intelligence, Electronic Data Systems Ann Arbor, MI (313) 995-0900 AppleLink: N0548 Internet: dave@cmi.com