Here is an overview of how user passwords are currently being stored in Plinth.
We check if the username or password is empty. If so, return an error message.
Use bcrypt (from passlib) to hash the password with a random salt. bcrypt returns the hash in the format:
2a
This hashed string will be used in step 5.
If the password length is over 4096, bcrypt raises an exception. We catch this exception and return an error message.
Check if the username exists in user store. If so, return an error message.
If no error has occurred so far, create the new user. The username, hashed password, and salt are stored in the user store database. The salt is a substring of the hash output by bcrypt.
We check if the username or password is empty. If so, return an error message.
Use bcrypt to hash the supplied password. This step is performed regardless of whether the user already exists. If the user exists, use the salt value stored for that user in the database, otherwise, a random salt is used.
If the password length is over 4096, bcrypt raises an exception. We catch this exception and return an error message.
Check if the user doesn't exist, or if the hashed password doesn't match the stored hash. Return an error message "Bad user-name or password" if either of these conditions are true.
If no error has occurred so far, return None to indicate that the supplied credentials are valid.