get_credential {dipsaus}R Documentation

Generate a random password


Please note that this function is not meant to be used in production. It is not meant to be used for highly secured cryptographic purposes.


  method = c("get_or_create", "replace", "query"),
  service = NULL,
  special_chr = "~`! @#$%^&*()_-+={[}]|:;'<,>.?/",
  tokenfile = NULL,
  verbose = FALSE



a master password that only you know, should have at least 8 characters


whether to query token map, or to create the password, choices are 'get_or_create' (default), 'replace', 'query'; see 'Details'


service name, must only contains letters, digits, equal sign, underscore, comma, dot, dash


special characters allowed in the password


a file containing all the tokens. Warning: if you lose the token book, it is hard (not impossible, but impractical) to restore the passwords


whether to print out service names; default is false


Please note that this function is not meant to be used in production or anything that requires high security level. This is most likely for my personal use since I am tired of storing the passwords on the cloud or having to buy the services.

The encryption adopts 'sha256' algorithm provided by digest function. To restore a password, you will need twp components: master_password, a token book ( tokenfile). If any of them is missing, then the password is lost. Please store the token book properly (for example, in 'Dropbox' vault).

The token book could be shared. Anyone who do not have master password will be unlikely to restore the service password. Do not share the master password with anyone other than yourself.

By default, method='get_or_create' will try to retrieve existing tokens to generate password. If the token is missing, then a new token will be generated. The method='replace' will ignore existing tokens and directly create a new one.


If method is 'query', returns token map; otherwise returns the password itself

See Also



tokenfile <- tempfile()

# ---------- Create a password and store the tokens to token book ------
pass1 <- get_credential(
  master_password = "my password",
  service = "",
  special_chr = "@#$%^&*",
  tokenfile = tokenfile

# ---------- Query existing tokens ------
token_params <- get_credential(
  method = "query",
  tokenfile = tokenfile,
  verbose = TRUE


# ---------- retrieve stored password ----------
pass2 <- get_credential(
  master_password = "my password",
  service = "",
  tokenfile = tokenfile
identical(pass1, pass2)

# Using wrong master password
pass3 <- get_credential(
  master_password = "wrong password",
  service = "",
  tokenfile = tokenfile
identical(pass1, pass3)

# ---------- Replace token ----------
# Existing token will be replaced with a new token
pass4 <- get_credential(
  master_password = "my password",
  method = "replace",
  service = "",
  special_chr = "@#$%^&*",
  tokenfile = tokenfile
identical(pass1, pass4)

[Package dipsaus version 0.2.5 Index]