check_credentials: Check credentials

View source: R/check_credentials.R

check_credentialsR Documentation

Check credentials

Description

Check credentials

Usage

check_credentials(db, passphrase = NULL)

Arguments

db

A data.frame with credentials data, a path to SQLite database created with create_db or a .yaml configuration path of SQL Database created with create_sql_db.

passphrase

Passphrase to decrypt the SQLite database.

Details

The credentials data.frame can have the following columns:

  • user (mandatory) : the user's name.

  • password (mandatory) : the user's password.

  • admin (optional) : logical, is user have admin right ? If so, user can access the admin mode (only available using a SQLite database). Initialize to FALSE if missing.

  • start (optional) : the date from which the user will have access to the application. Initialize to NA if missing.

  • expire (optional) : the date from which the user will no longer have access to the application. Initialize to NA if missing.

  • applications (optional) : the name of the applications to which the user is authorized, separated by a semicolon. The name of the application corresponds to the name of the directory, or can be declared using : options("shinymanager.application" = "my-app")

  • additional columns : add others columns to retrieve the values server-side after authentication

Value

Return a function with two arguments: user and password to be used in module-authentication. The authentication function returns a list with 4 slots :

  • result : logical, result of authentication.

  • expired : logical, is user has expired ? Always FALSE if db doesn't have a expire column.

  • authorized : logical, is user can access to his app ? Always TRUE if db doesn't have a applications column.

  • user_info : the line in db corresponding to the user.

See Also

create_db, create_sql_db, check_credentials

Examples

# data.frame with credentials info
credentials <- data.frame(
  user = c("fanny", "victor"),
  password = c("azerty", "12345"),
  stringsAsFactors = FALSE
)

# check a user
check_credentials(credentials)("fanny", "azerty")
check_credentials(credentials)("fanny", "azert")
check_credentials(credentials)("fannyyy", "azerty")

# data.frame with credentials info
# using hashed password with scrypt
credentials <- data.frame(
  user = c("fanny", "victor"),
  password = c(scrypt::hashPassword("azerty"), scrypt::hashPassword("12345")),
  is_hashed_password = TRUE,
  stringsAsFactors = FALSE
)

# check a user
check_credentials(credentials)("fanny", "azerty")
check_credentials(credentials)("fanny", "azert")
check_credentials(credentials)("fannyyy", "azerty")

## Not run: 

## With a SQLite database:
check_credentials("credentials.sqlite", passphrase = "supersecret")


## With a SQL database:
check_credentials("config_db.yml")


## End(Not run)


datastorm-open/shinymanager documentation built on Nov. 3, 2023, 10:51 p.m.