Way to Securely Give a Password to R Application from the Terminal

Ask user crendentials when running R in Terminal

getPass is your best solution.

It supports RStudio and fallsback to tcltk and other backends if missing.

password <- getPass::getPass() is your call.

How do I input username and password in R securely without details showing up in console?

Have you tried creating a secure folder and putting a text file in it with your logon credentials?
You could just call that and reference the inputted variables in your connection string.

Just not sure if it will come up in the console when you connect or not..

Get password from R console

You need a UI component that knows a password is typed, and hence shows the stars.

The only portable one is part of the tcltk package, and has been recommended a few times in the past.

Edit: The getPass package provides a wrapper to several underlying approaches.

Reading user input (like passwords) in R without echoing (for Windows OS)

This blog post by Markus Gesmann has the solution of what I was looking for: Simple user interface in R to get login details

R Login pop-up

The following function getLoginDetails() uses the R packages tcltk and gWidgetstcltk to get the login details in a pop-up window:

getLoginDetails <- function(){
## Based on code by Barry Rowlingson
## http://r.789695.n4.nabble.com/tkentry-that-exits-after-RETURN-tt854721.html#none
require(tcltk)
tt <- tktoplevel()
tkwm.title(tt, "Get login details")
Name <- tclVar("Login ID")
Password <- tclVar("Password")
entry.Name <- tkentry(tt,width="20", textvariable=Name)
entry.Password <- tkentry(tt, width="20", show="*",
textvariable=Password)
tkgrid(tklabel(tt, text="Please enter your login details."))
tkgrid(entry.Name)
tkgrid(entry.Password)

OnOK <- function()
{
tkdestroy(tt)
}
OK.but <-tkbutton(tt,text=" Login ", command=OnOK)
tkbind(entry.Password, "<Return>", OnOK)
tkgrid(OK.but)
tkfocus(tt)
tkwait.window(tt)

invisible(c(loginID=tclvalue(Name), password=tclvalue(Password)))
}
credentials <- getLoginDetails()
## Do what needs to be done
## Delete credentials
rm(credentials)

How do I prevent exposure of my password when using RGoogleDocs?

My approach is to set the login-name & password in the R options list
within the R startup file .Rprofile. Then my code gets the value
with getOption() and then the value is never visible or stored
in a top-level variable in globalenv(). (It could be save if
one does post-mortem debugging via dump.frames).

It is vital that the .Rprofile cannot be read by anybody other than you.

So

options(GoogleDocsPassword = c(login = 'password'))

in the .Rprofile and then

auth = getGoogleAuth()

just works as the default value for the first parameter is to look for the GoogleDocsPassword option.

D.

Reading user input without echoing

What's the operating system? If you can run it from a terminal, this should work.

get_password <- function() {
cat("Password: ")
system("stty -echo")
a <- readline()
system("stty echo")
cat("\n")
return(a)
}

> a <- get_password()
Password:
> a
[1] "sdfs"
>

This works on OS X using R from Terminal.app, but not from R.app. No idea on a Windows solution, since there doesn't seem to be a native R solution.

How to make a secure password input field in a command line app?

Just for the sake of completeness: getpass() works great for passwords, but unfortunately this function also has the limitation that it can only read up to 128 characters. If you want to prompt for really long passphrase or private keys, use BSD's readpassphrase() instead.

Swift 2.0 example:

var buf = [Int8](count: 8192, repeatedValue: 0)
let passphrase = readpassphrase("Enter passphrase: ", &buf, buf.count, 0)
if let passphraseStr = String.fromCString(passphrase) {
print(passphraseStr)
}

Swift 3.1 and later:

var buf = [CChar](repeating: 0, count: 8192)
if let passphrase = readpassphrase("Enter passphrase: ", &buf, buf.count, 0),
let passphraseStr = String(validatingUTF8: passphrase) {

print(passphraseStr)
}


Related Topics



Leave a reply



Submit