从终端安全地为 R 应用程序提供密码的方法? [英] Way to securely give a password to R application from the terminal?
问题描述
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 应用程序提供密码的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!