r-lib / keyring

:closed_lock_with_key: Access the system credential store from R
https://keyring.r-lib.org/
Other
196 stars 28 forks source link

`key_get` with `username=NULL` returns password from first entry #75

Closed benjaminleroy closed 5 years ago

benjaminleroy commented 5 years ago

After initializing a different keyring with a few values, it appears that if I put in NULL or "" in for the username in key_get(), then I will get the password back for the first individual I put it. Is this on purpose?

Demo code:

library(keyring)

keyring_list() # should just see default/login keyring
keyring_create("shiny-keyring")
key_set_with_value("test-service", "Ben", password = "Banana",
                   keyring = "shiny-keyring")
key_set_with_value("test-service", "Nic", password = "Apple",
                   keyring = "shiny-keyring")
key_list(keyring = "shiny-keyring") # should see my username
key_get("test-service", "Ben",keyring = "shiny-keyring") # should show my password

key_get("test-service", NULL, keyring = "shiny-keyring") # awkward
key_get("test-service", "", keyring = "shiny-keyring") # awkward

on my machine, both of the last 2 lines return "Banana".

gaborcsardi commented 5 years ago

Yes, it is intentional. Sometimes you don't even have a username, actually.

benjaminleroy commented 5 years ago

thanks - it seems weird for my application - but sounds good. Thanks for the great package.