2010-05-26 9 views

Odpowiedz

27

Problem polega na tym, że R nie posiada funkcje kontroli terminal jest uruchomiony w (coś jak Rncurses); prawdopodobnie wynika to z problemów z przenośnością.
Jakiś czas temu miałem problemy z tym samym problemem i skończyło się z funkcją z wykorzystaniem 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); 
} 

Oczywiście to nie będzie działać w środowiskach non-GUI.

+0

Działa idealnie jak w reklamie. Dzięki! – A5C1D2H2I1M1N2O1R2T1

+0

Po prostu znalazłem to zaimplementowane w funkcji 'getPass :: getPass()'. –

5

Bardzo prosta koncepcja linux dla terminala bezpiecznego pytanie hasłem:

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

Nie działa dla mnie. Mięta 18.2. '' ''> hasło() Hasło: stty: 'standardowe wejście': niewłaściwe ioctl dla urządzenia Komunikat ostrzegawczy: komenda "stty -echo && read ff && stty echo && echo $ ff && ff =" " status 1 '' ' – Deleet

1

Mój pakiet keyringr rozwiązuje ten problem poprzez pobieranie haseł z podstawowej kluczy systemu operacyjnego (DPAPI w systemie Windows, pęku kluczy na OSX i Gnome Brelok na Linuksie).

vignette podaje szczegółowe wyjaśnienie, w jaki sposób korzystać z pakietu, ale jeśli były przy użyciu OSX i mają hasło zapisane w pęku kluczy, można użyć następującego polecenia, aby przywrócić hasło do R (gdzie mydb_myuser jest Brelok nazwa elementu):

install.packages("keyringr") 
library("keyringr") 
mypwd <- decrypt_kc_pw("mydb_myuser") 
print(mypwd) 
+0

Otrzymuję komunikat' Błąd: Sys.info() ["sysname"] == "Darwin" nie jest PRAWDĄ ". Co to znaczy? Czy powinienem nacisnąć "Alt-Right"? –

+0

Jakiego systemu operacyjnego używasz? Proszę zgłoś problem na stronie github.com/jgilfillan/keyringr. dzięki. –

+0

'" Darwin "nie jest TRUE' jest w systemie Windows. –

0

Oto logowanie wyskakujące na podstawie ?modalDialog.

library("shiny") 

shinyApp(
    ui <- basicPage(
    actionButton("login", "Login"), 
    verbatimTextOutput("secrets") 
), 

    server <- function(input, output, session) { 
    vals <- reactiveValues(authenticated=FALSE) 

    passwordModal <- function(message=NULL) { 
     modalDialog(
     textInput("username", "Username", input$username), 
     passwordInput("password", "Password", input$password), 

     if (!is.null(message)) div(tags$b(message, style="color: red;")), 

     footer = tagList(
      modalButton("Cancel"), 
      actionButton("authenticate", "OK") 
     ) 
    ) 
    } 

    observeEvent(input$login, { 
     showModal(passwordModal()) 
    }) 

    observeEvent(input$authenticate, { 
     vals$authenticated <- FALSE 
     if (!is.null(input$username) && nzchar(input$username) && 
      !is.null(input$password) && nzchar(input$password)) { 
     removeModal() 

     if (input$password == "letmein") { 
      vals$authenticated <- TRUE 
     } else { 
      showModal(passwordModal(message="Incorrect password!")) 
     } 

     } else { 
     showModal(passwordModal(message="Please fill in your username and password")) 
     } 
    }) 

    output$secrets <- renderText({ 
     if (vals$authenticated) { 
     paste("Don't tell anyone, ", input$username, ", but...", sep="") 
     } else { 
     "I can't tell you that!" 
     } 
    }) 
    } 
) 
1

Per m-dz w powyższych uwag, istnieje obecnie pakiet ten sposób nazywa getPass, który ma jedną funkcję, getPass(). To jest zamiennik dla base::readline().

enter image description here

Powiązane problemy