Subject: Re: Password problem - DN [1]


Csaba.Nemethi@t-online.de (Csaba Nemethi) - 25 Apr 1999 - comp.lang.tcl

 Henk-Jan Kooiman wrote:

 > Perhaps I missed something, but when I read the documentation of TK
 > the next example should work:
 >
 > entry .pw -width 20 -show *
 > pack .pw
 >
 > Well, it works fine. I see *'s, but when I copy the *'s
 > and paste it into an editor I get: "This was my password :-)".
 > According to the documentation I should see: "************************"
 >
 > What's wrong:
 > a. the documentation
 >    or
 > b. tcl/tk 8.05 (mac and win)
 >
 > If a., does anyone know how to secure a password on the screen?
 >
 > Thanks,
 >
 > Henk-Jan Kooiman
 > hjk@cable.a2000.nl

 The -show option works as expected in an X11 environment, but not on
 Windows (and Mac?).  This bug was reported some weeks ago to Scriptics
 (I saw the posting in this newsgroup), but I have no idea when it gets
 fixed.

 There is, however, a workaround based on the widget callback package
 Wcb, which you can download from the URL http://www.nemethi.de.  Install
 the package as described in the file README.txt and proceed as follows:

      package require Wcb

      #
      # Visible entry with before-insert and before-delete callbacks
      #
      entry .pw -width 20
      pack .pw
      wcb::callback .pw before insert {wcb::checkEntryLen 20} insertCb
      wcb::callback .pw before delete deleteCb

      #
      # Invisible entry holding the password
      #
      entry .shadow -textvar passwd

      #
      # Before-insert callback insertCb
      #
      proc insertCb {w idx str} {
          #
          # In the visible entry, replace the string with * characters
          #
          set len [string length $str]
          for {set i 0} {$i < $len} {incr i} {
              append stars *
          }
          wcb::replace 1 1 $stars

          #
          # Insert the original string into the invisible entry
          #
          .shadow insert [$w index $idx] $str
      }

      #
      # Before-delete callback deleteCb
      # The parameter args stands for "first ?last?"
      #
      proc deleteCb {w args} {
          #
          # Delete the given text area from the invisible entry
          #
          foreach idx $args {
              lappend indices [$w index $idx]
          }
          eval .shadow delete $indices
      }

 The above code works on every platform.  The wcb::checkEntryLen callback
 is optional but useful: it prevents the user from inserting more than 20
 characters.  The entry .pw will contain pure * characters; the password
 will be inserted into the invisible entry .shadow and also held in the
 variable passwd.

 --
 Csaba Nemethi   http://www.nemethi.de   mailto:csaba.nemethi@t-online.de

Last modified
1999-09-27

(195.108.246.50)

Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated