Skip to content

adjunct.passkit

A partial replacement for passlib.

Implementing an equivalent of its HtpasswdFile class and supporting functionality.

It comes with a simple tool for manipulating JSONPasswd files.

JSONPasswdFile

A class to manage user credentials stored in a JSON file.

File Format

The JSON file should contain a dictionary where keys are usernames and values are structured data for checking password validity.

The outer structure is as follows:

{
  "metadata": {
    "type": "tag:talideon.com,2025:jsonpasswd",
    "version": 1
  },
  "users": {
    "<username1>": { ... },
    "<username2>": { ... }
  }
}

For the benefit of tools like file(1), the file should start with the metadata entry.

Each value entry has the format:

{
  "alg": "scrypt",
  "key": "<hashed_password>",
  "salt": "<salt_value>",
  "params": {
    "n": <N_value>,
    "r": <r_value>,
    "p": <p_value>
  }
}

Note that the salt and hashed password key are base64-encoded.

Currently only the "scrypt" algorithm is supported.

Warning

it is the user's responsibility to lock the file if necessary to prevent concurrent access.

Parameters:

Name Type Description Default
filepath str

the path to use when loading/saving the file

required
implementation str

the method to use for encrypting the passwords; only "scrypt" is currently supported.

'scrypt'

Attributes:

Name Type Description
filepath str

the path to use when loading/saving the file

check_password(username, password)

Check is a user's password is valid.

This verifies the provided password against the stored credentials for the given user.

Parameters:

Name Type Description Default
username str

the username whose password must be validated

required
password str

the plaintext password to validate

required

Returns:

Type Description
bool

True if the password is correct; False if the user doesn't exist or the password is invalid.

Raises:

Type Description
UnknownAlgorithmError

the password does not use a known algorithm

delete(username)

Remove the given user from the database.

Parameters:

Name Type Description Default
username str

the user to remove

required

Returns:

Type Description
bool

True if the user was found and removed; False if the user was not found.

set_password(username, password)

Set the given user's password.

Parameters:

Name Type Description Default
username str

the user's username

required
password str

the new password

required
Note

Calling this method will immediately save the file.

UnknownAlgorithmError

Bases: Exception

Raised when an entry has either an unknown algorithm or none.