:tocdepth: 3 :py:mod:`gws.lib.password` ========================== .. py:module:: gws.lib.password .. autoapi-nested-parse:: Password tools. **Source code:** :source:`gws.lib.password` Package Contents ---------------- .. py:function:: check(password: str, encoded: str) -> bool Check if a password matches a hash. :param password: Password as a string. :param encoded: Hash of the input password as a string. :returns: ``True`` if password matches the hash, else ``False``. .. py:function:: compare(a: str, b: str) -> bool Compares two Strings in a safe way to prevent timing attacks. :param a: 1st String. :param b: 2nd String. :returns: ``True`` if a equals b, ``False`` otherwise. .. py:function:: encode(password: str, algo: str = 'sha512') -> str Encode a password into a hash. :param password: String password. :param algo: Hashing algorithm. Default is SHA512. :returns: Respective hash value in the format ``$algorithm$salt$hash``. .. py:function:: generate(min_len: int = 16, max_len: int = 16, min_lower: int = 0, max_lower: int = 255, min_upper: int = 0, max_upper: int = 255, min_digit: int = 0, max_digit: int = 255, min_punct: int = 0, max_punct: int = 255) -> str Generate a random password. .. py:function:: generate_with_groups(groups: list[SymbolGroup], min_len: int = 16, max_len: int = 16) -> str Generate a random password from a list of `SymbolGroup` objects. .. py:class:: SymbolGroup(s, min_len, max_len) .. py:attribute:: chars .. py:attribute:: count :value: 0 .. py:attribute:: max .. py:attribute:: min