Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


hide a password in tcl

hide a password in tcl

hide a password in tcl

I know I may sound naive but is it possible to hide/mask the user input in a gets stdin command. I want to do this in my script which accepts user input for password

puts -nonewline stdout "Please enter the password: ";

#want to mask/hide the input text here
gets stdin wspasswd;

I tried searching around but only got code specific to OS/DB. Is there nothing on TCL level itself to get this done

Any help will be greatly appreciated.


RE: hide a password in tcl

I don't think you can do it without using Tk (like in an entry widget).

Bob Rashkin

RE: hide a password in tcl

Hi Bob

I am sorry but I am not too aware of Tk and how it can work alongside Tcl. is it as simple as

set passwd makeentry(parent, "Password:", 10, show="*");

can you illustrate a very basic example please?

RE: hide a password in tcl

I's possible, but you need a package called Expect.
Long time ago I wrote a function getpass, here is it:


proc getpass {prompt} {
  # Required package is Expect. It could be installed using teacup:
  # teacup install Expect
  package require Expect
  set oldmode [stty -echo -raw]
  send_user "$prompt"
  set timeout -1
  expect_user -re "(.*)\n"
  send_user "\n"
  eval stty $oldmode
  return $expect_out(1,string)

Here is an example, how to use it:


### Enter Login-Data
puts -nonewline stdout "AS/400 name : "; flush stdout; set csebk  [gets stdin] 
puts -nonewline stdout "User Id     : "; flush stdout; set userid [gets stdin]
# Using getpass for getting password
source getpass.tcl
set pass  [getpass "Password    : "]
puts {}
puts "You entered password : \"$pass\"" 



C:\Work>tclsh85 getpass_usage.tcl
AS/400 name : myAS400
User Id     : mikrom
Password    :

You entered password : "mikroms_password" 

RE: hide a password in tcl

@mikrom, very cool.
@birdy1980, Tk is the windowing package(s) that work with Tcl. You would need to run the WIndowSHell, "wish", instead of the Tcl Shell, "tclsh". Then you would build a GUI and... It's probably better to use Expect and mikrom's solution.

Bob Rashkin

RE: hide a password in tcl

My first scripting language was Python. It's standard library contains a module getpass with function getpass(). Later I started to learn other scripting languages too.
To evaluate if a new language could be usable for my needs and to compare the languages, I first try to implement in every language the same simple example, i.e. how to retrieve data from database on IBM iSeries (aka AS/400). For database login I need a function for getting user password without echo - something like getpass() in Python.
So - as time passed - I wrote function getpass() for IronPython, Perl, Tcl, REXX, VBscript and Lua.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close