Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rstudioapi askForPassword without masking for username entry

Is there a way to disable the masking in the rstudioapi::askForPassword pop up window so a user can enter their username?

I am building a function I can share with my team for connecting to our Oracle DB instance using the ROracle pacakge

Current solution,

  connection <- dbConnect(
    driver
    , username = rstudioapi::askForPassword(prompt = 'Please enter username: ')
    , password = rstudioapi::askForPassword(prompt = 'Password: ')
    , dbname = 'my.connection.string'
  )

This pops up the following prompt: (image in link)

which is the solution described in the RStudio database docs that uses the Rstudio api

Would like to fund a solution that does not mask the password but pops up the same prompt (one nice line of code if possible...)

like image 641
blakiseskream Avatar asked Sep 06 '17 16:09

blakiseskream


2 Answers

If you are using the preview version of RStudio (1.1.67+) there are newer functions available to you in the rstudioapi package, showPrompt seems to accomplish what you are after.

connection <- dbConnect(
    driver,
    username = rstudioapi::showPrompt(
      title = "Username", message = "Username", default = ""
    ),
    password = rstudioapi::askForPassword(prompt = "Password"),
    dbname = "my.connection.string"
)
like image 50
Kevin Arseneau Avatar answered Nov 15 '22 00:11

Kevin Arseneau


For newer versions of rstudioapi::askForPassword I noticed the following...

  • If you just include the string username in your argument phrase, the text is unmasked.
  • Including password will strictly enforce masking.

For example:

rstudioapi::askForPassword("Enter username") # <-- UNMASKED
rstudioapi::askForPassword("Enter password") # <-- MASKED

rstudioapi::askForPassword("Enter foobar xyz123 username") # <-- UNMASKED
rstudioapi::askForPassword("Enter foobar xyz123 username password") # <-- MASKED 

I stumbled on this by accident of course, in that the pw prompted text box automatically unmasks for username... There could be more info at:

  • https://rdrr.io/cran/rstudioapi/man/askForPassword.html
  • https://cran.rstudio.com/web/packages/rstudioapi/rstudioapi.pdf
like image 27
Etienne Jacquot Avatar answered Nov 15 '22 00:11

Etienne Jacquot