watson.auth.authentication

class watson.auth.authentication.Authenticator(config, session, user_model, user_id_field, email_field)[source]

Authenticates a user against the database.

session

The SqlAlchemy session to use.

user_model

string – The class name of the user model.

user_id_field

string – The field that is to be used as the username.

__init__(config, session, user_model, user_id_field, email_field)[source]
assign_user_to_session(user, request, session_key)[source]

Assign a user to the session.

authenticate(username, password)[source]

Validate a user against a supplied username and password.

Parameters:
  • username (string) – The username of the user.
  • password (string) – The password of the user.
get_user(username)[source]

Retrieves a user from the database based on their username.

Parameters:username (string) – The username of the user to find.
get_user_by_id(id)[source]

Retrieves a user from the database based on their id.

Parameters:id (int) – The id of the user to find.
get_user_by_username_or_email(data)[source]

Retrieves a user from the database based on their user or email.

Parameters:data (string) – The username/email of the user to find.
watson.auth.authentication.check_password(password, existing_password, salt, encoding='utf-8')[source]

Validate a password against an existing password and the salt used to generate it.

Parameters:
  • password (string) – The password to validate
  • existing_password (string) – The password to validate against
  • salt (string) – The salt used to generate the existing_password
Returns:

True/False if valid or invalid

Return type:

boolean

watson.auth.authentication.generate_password(password, rounds=10, encoding='utf-8')[source]

Generate a new password based on a random salt.

Parameters:
  • password (string) – The password to generate the hash off
  • rounds (int) – The complexity of the hashing
Returns:

The generated password and the salt used

Return type:

mixed