Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

how to accept password using Tk

by pg (Canon)
on Feb 08, 2003 at 19:45 UTC ( [id://233762]=perlquestion: print w/replies, xml ) Need Help??

pg has asked for the wisdom of the Perl Monks concerning the following question:

I am doing something, and need to let the users enter their passwords. Obviously, I don't want to see their passwords being displayed on the screen, instead I should see ******.

I am using Tk::Text, but sounds like it does not support this. I mean I can control this by myself, by catching key-pressed event, and convert the password into "****", before display them. But I prefer not to reinvent anything if it is there already.

My question is:
  1. Did I miss anything about Tk::Text?
  2. or maybe I should use a different Tk widget? (I prefer to use core modules come with standard perl distribution, unless that is impossible)

Replies are listed 'Best First'.
Re: how to accept password using Tk
by Nitrox (Chaplain) on Feb 08, 2003 at 20:32 UTC
    Use Tk::Entry instead:
    $MainWindow->Entry( -show=>'*', -relief=>'ridge', -textvariable=>\$password )->pack;

    -Nitrox

      Great, both of you are great, Now I am doing something like this:
      use strict; use Tk; use Tk::DialogBox; my $mw = new MainWindow(); my $dialog = $mw->DialogBox(-title => "Login", -buttons => ["OK", "Cancel"]); my $id = $dialog->add("Entry") ->pack(); my $passwd; my $password = $dialog->add("Entry", -show => "*", -textvariable => \$passwd) ->pack(); if ($dialog->Show() eq "OK") { print $passwd, "\n";#this line is only for demo } MainLoop;
      I always use Text(height => 1) for one-line entries, and now I realize that for lots of those places, actually I should use Entry instead. Thanks again, have a great day.
Re: how to accept password using Tk
by grantm (Parson) on Feb 08, 2003 at 20:19 UTC
Re: how to accept password using Tk
by zentara (Archbishop) on Feb 09, 2003 at 15:25 UTC
    Here's a version you might like:
    #!/usr/bin/perl use Tk; my $MainWindow = MainWindow->new; $MainWindow->title("Password Entry"); $MainWindow -> Label(-justify => 'left', -text => "Name : ") ->pack(); my $entry = $MainWindow -> Entry(-selectborderwidth => 10) ->pack(); $MainWindow -> Label(-justify => 'left', -text => "Password: ") ->pack(); my $entry1 = $MainWindow -> Entry(-selectborderwidth => 10, -show => "*") ->pack(); $MainWindow -> Button(-text => "SUBMIT", -command => \&somesub) ->pack(-side => 'bottom',-anchor => 'center'); $entry->bind('<Return>',[\&somesub]); $entry->focus; MainLoop; sub somesub { $name = $entry -> get; $password = $entry1->get; print "name ->$name\n"; print "password ->$password\n"; $MainWindow -> destroy; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://233762]
Approved by pfaut
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-03-29 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found