absfuyu.tools.passwordlib module

Absfuyu: Passwordlib

Password library

Version: 5.1.0 Date updated: 10/03/2025 (dd/mm/yyyy)

class absfuyu.tools.passwordlib.PasswordGenerator[source]

Bases: BaseClass

Password Generator

Added in version 4.2.0

static password_hash(password: str) PasswordHash[source]

Generate hash for password.

Parameters:

password (str) – Password string

Returns:

Password hash contains salt and key

Return type:

PasswordHash

static password_check(password: str) dict[source]

Check password’s characteristic.

Parameters:

password (str) – Password string

Returns:

Password’s characteristic.

Return type:

dict

static generate_password(length: int = 8, include_uppercase: bool = True, include_number: bool = True, include_special: bool = True) str[source]

Generate a random password.

Parameters:
  • length (int) –

    Length of the password.
    Minimum value: 8
    (Default: 8)

  • include_uppercase (bool) – Include uppercase character in the password, by default True

  • include_number (bool) – Include digit character in the password, by default True

  • include_special (bool) – Include special character in the password, by default True

Returns:

Generated password

Return type:

str

Example:

>>> Password.generate_password()
[T&b@mq2
static generate_passphrase(num_of_blocks: int = 5, block_divider: str | None = None, first_letter_cap: bool = True, include_number: bool = True, *, custom_word_list: list[str] | None = None) str[source]

Generate a random passphrase

Parameters:
  • num_of_blocks (int) – Number of word used, by default 5

  • block_divider (str) – Character symbol that between each word, by default "-"

  • first_letter_cap (bool) – Capitalize first character of each word, by default True

  • include_number (bool) – Add number to the end of each word, by default True

  • custom_word_list (list[str] | None) – Custom word list for passphrase generation, by default uses a list of 360K+ words

Returns:

Generated passphrase

Return type:

str

Example:

>>> print(Password().generate_passphrase())
Myomectomies7-Sully4-Torpedomen7-Netful2-Begaud8
class absfuyu.tools.passwordlib.PasswordHash(salt: bytes, key: bytes)[source]

Bases: NamedTuple

Password hash

Parameters:
  • salt (bytes) – Salt

  • key (bytes) – Key

salt: bytes

Alias for field number 0

key: bytes

Alias for field number 1

class absfuyu.tools.passwordlib.TOTP(secret: str, name: str | None = None, issuer: str | None = None, algorithm: Literal['SHA1', 'SHA256', 'SHA512'] = 'SHA1', digit: int = 6, period: int = 30)[source]

Bases: BaseClass

A class to represent a Time-based One-Time Password (TOTP) generator.

Parameters:
  • secret (str) – The shared secret key used to generate the TOTP.

  • name (str, optional) –

    The name associated with the TOTP.
    If not provided, by default "None".

  • issuer (str, optional) – The issuer of the TOTP.

  • algorithm (Literal["SHA1", "SHA256", "SHA512"], optional) –

    The hashing algorithm used to generate the TOTP.
    Must be one of "SHA1", "SHA256", or "SHA512".
    By default "SHA1".

  • digit (int, optional) –

    The number of digits in the generated TOTP.
    Must be greater than 0.
    By default 6.

  • period (int, optional) –

    The time step in seconds for TOTP generation.
    Must be greater than 0.
    by default 30.

Added in version 5.0.0

URL_SCHEME: ClassVar[str] = 'otpauth://totp/'
to_url() str[source]

Generates a URL for the TOTP in the otpauth format.

The URL format is as follows:

otpauth://totp/<name>?secret=<secret>&issuer=<issuer>&algorithm=<algorithm>&digit=<digit>&period=<period>

Returns:

A URL representing the TOTP in otpauth format.

Return type:

str