Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect password when quickly pressing enter #195

Open
kamilzyla opened this issue Jul 29, 2024 · 2 comments
Open

Incorrect password when quickly pressing enter #195

kamilzyla opened this issue Jul 29, 2024 · 2 comments

Comments

@kamilzyla
Copy link

If I type the username and password quickly and immediately press ENTER I get the "Username or password are incorrect" error. I am logged in correctly if I press ENTER again or if I make a short pause after typing the password.

I have used this trivial app for testing:

library(shiny)
library(shinymanager)

credentials <- data.frame(
  user = c("admin"),
  password = c("admin")
)

shinyApp(
  ui = secure_app("Hello!"),
  server = function(input, output) {
    secure_server(check_credentials = check_credentials(credentials))
  }
)
@r-a-qureshi
Copy link

r-a-qureshi commented Aug 14, 2024

I was struggling with this same issue and I came up with a workaround to solve this problem. Basically, I'm using javascript to capture the "enter" keypress, block the default event (the action that is normally supposed to happen on keypress) and then use javascript to add a time delay and then activate the log in button. Here's an example script:

library(shiny)
library(shinymanager)
library(shinyjs)

js <- "
pressbtn = function(){

    // click the log in button
    document.getElementById('auth-go_auth').click();
};
window.onload = function() {

// password input field
const field = document.getElementById('auth-user_pwd');

// add a function that preempts the enter key press
field.addEventListener('keydown',  
function(e) {

    if (e.keyCode == 13) {
    // prevent sending the key event
    e.preventDefault();
   
    // delay activating the login button for 400 ms. adjust time as needed
    setTimeout(pressbtn,400);
    };

});
}
"
credentials <- data.frame('user'=c('test'),password=c('pass'))

# pass script tag to head_auth variable which will insert our script into the header
ui <- secure_app(fluidPage('Hello World!'),head_auth = tags$script(js))

server <- function(input,output,session) {
    res_auth <- secure_server(
        check_credentials = check_credentials(credentials)
    )
}

shinyApp(ui=ui,server=server)

Here's the javascript code with syntax highlighting:

pressbtn = function(){

    // click the log in button
    document.getElementById('auth-go_auth').click();
};
window.onload = function() {

// password input field
const field = document.getElementById('auth-user_pwd');

// add a function that preempts the enter key press
field.addEventListener('keydown',  
function(e) {

    if (e.keyCode == 13) {

    // prevent sending the key event
    e.preventDefault();
   
    // delay activating the login button for 400 ms. adjust time as needed
    setTimeout(pressbtn,400);
    };

});
}

@munoztd0
Copy link

thank you !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants