gws.lib.password
¶
Password tools.
Source code: gws.lib.password
Package Contents¶
- gws.lib.password.check(password: str, encoded: str) bool ¶
Check if a password matches a hash.
- Parameters:
password – Password as a string.
encoded – Hash of the input password as a string.
- Returns:
True
if password matches the hash, elseFalse
.
- gws.lib.password.compare(a: str, b: str) bool ¶
Compares two Strings in a safe way to prevent timing attacks.
- Parameters:
a – 1st String.
b – 2nd String.
- Returns:
True
if a equals b,False
otherwise.
- gws.lib.password.encode(password: str, algo: str = 'sha512') str ¶
Encode a password into a hash.
- Parameters:
password – String password.
algo – Hashing algorithm. Default is SHA512.
- Returns:
Respective hash value in the format
$algorithm$salt$hash
.
- gws.lib.password.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.
- gws.lib.password.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.
- class gws.lib.password.SymbolGroup(s, min_len, max_len)¶