如何从终端安全地给R应用程序提供密码?

Ham*_*mer 34 passwords r input password-protection

R是否具有允许用户安全地提供密码的功能,例如Python的getpass模块?

(请参阅http://docs.python.org/library/getpass.html以获取我的意思)

mbq*_*mbq 27

问题是R没有控制它运行的终端的功能(类似的东西Rncurses); 可能这是由于可移植性问题.
前段时间我正在努力解决同样的问题,最后我使用了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);  
}  
Run Code Online (Sandbox Code Playgroud)

当然,它不适用于非GUI环境.


小智 5

终端安全密码问题非常简单的linux概念:

   password <- function(prompt = "Password:"){
      cat(prompt)
      pass <- system('stty -echo && read ff && stty echo && echo $ff && ff=""',
                        intern=TRUE)
      cat('\n')
      invisible(pass)
   }        
Run Code Online (Sandbox Code Playgroud)


Del*_*eet 5

根据上面评论中的m-dz,现在有一个用于执行此操作的包,称为getPass,它具有单个函数getPass(). 这是base::readline().

在此处输入图片说明