[R] readline() for passwords?
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Thu Feb 16 11:27:45 CET 2006
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
More information about the R-help
mailing list