python_template_server.authentication_handler

Authentication handler for the server.

Functions

generate_new_token()

Generate a new token, hash it, and save the hash to the .env file.

generate_token()

Generate a secure random token.

hash_token(token)

Hash a token string using SHA-256.

save_hashed_token(token)

Hash a token and save it to the .env file.

verify_token(token, hashed_token)

Verify a token against the stored hash.

python_template_server.authentication_handler.generate_token()[source]

Generate a secure random token.

Return str:

A URL-safe token string

Return type:

str

python_template_server.authentication_handler.hash_token(token)[source]

Hash a token string using SHA-256.

Parameters:

token (str) – The plain text token to hash

Return str:

The hexadecimal representation of the hashed token

Return type:

str

python_template_server.authentication_handler.save_hashed_token(token)[source]

Hash a token and save it to the .env file.

Parameters:

token (str) – The plain text token to hash and save

Return type:

None

python_template_server.authentication_handler.verify_token(token, hashed_token)[source]

Verify a token against the stored hash.

Parameters:
  • token (str) – The plain text token to verify

  • hashed_token (str) – The stored hashed token for comparison

Return bool:

True if the token matches the stored hash, False otherwise

Return type:

bool

python_template_server.authentication_handler.generate_new_token()[source]

Generate a new token, hash it, and save the hash to the .env file.

This function generates a new secure random token, hashes it using SHA-256, and saves the hashed token to the .env file for future verification.

Return type:

None