gws.lib.password

Password tools.

Source code: gws.lib.password

Package Contents

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.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, else False.