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
|
|
Raises:
| Type | Description |
|---|---|
UnknownAlgorithmError
|
the password does not use a known algorithm |