本文介绍了如何从终端安全地向R应用程序提供密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
R是否具有允许用户安全地提供密码的功能,例如Python的getpass
模块?
Does R have a function that allows a user to provide a password securely, such as Python's getpass
module?
(请参见 http://docs.python.org/library/getpass.html举例说明我的意思
(see http://docs.python.org/library/getpass.html for an example of what I mean)
推荐答案
问题是R没有控制它运行的终端的功能(类似于Rncurses
);可能是由于可移植性问题.
不久前,我在同一个问题上苦苦挣扎,最后使用TclTk获得了一个函数:
The problem is that R does not have functions to control the terminal it is running in (something like Rncurses
); probably this is due to portability issues.
Some time ago I was struggling with the same problem and I ended up with a function using TclTk:
getPass<-function(){
require(tcltk);
wnd<-tktoplevel();tclVar("")->passVar;
#Label
tkgrid(tklabel(wnd,text="Enter password:"));
#Password box
tkgrid(tkentry(wnd,textvariable=passVar,show="*")->passBox);
#Hitting return will also submit password
tkbind(passBox,"<Return>",function() tkdestroy(wnd));
#OK button
tkgrid(tkbutton(wnd,text="OK",command=function() tkdestroy(wnd)));
#Wait for user to click OK
tkwait.window(wnd);
password<-tclvalue(passVar);
return(password);
}
当然,它不能在非GUI环境中使用.
Of course it won't work in non-GUI environments.
这篇关于如何从终端安全地向R应用程序提供密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!