Re: [R] readline() for passwords?

From: Barry Rowlingson <B.Rowlingson_at_lancaster.ac.uk>
Date: Thu 16 Feb 2006 - 21:27:45 EST

Ulf Mehlig wrote:

> I am using RODBC to access a password-protected database. Is there a
> possibility to prevent that the password appears on the screen when
> issuing the odbcConnect() command? I thought of something like
> readline() without echo. I guess that a getpass()-based solution
> wouldn't work for ESS/Emacs, anyway, would it?

tk has a way of doing this, so you can build a function that uses the tcltk package. Something like:

getPassword <- function(){

   require(tcltk)
   tt <- tktoplevel()
   pass=tclVar("")
   label.widget <- tklabel(tt, text="Enter Password")    password.widget <- tkentry(tt,show="*",textvariable=pass)    ok <- tkbutton(tt,text="Ok",command=function()tkdestroy(tt))    tkpack(label.widget, password.widget,ok)    tkwait.window(tt)
   return(tclvalue(pass))
}

The vital part here is the 'show="*"' option in the tkentry widget.

Of course this is no use if you aren't in a graphical environment at the time.

Barry



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Feb 16 21:40:25 2006

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 14:08:29 EST