This is a template for simple user authentication with FastAPI. It handles the following tasks:
- storage of user credentials
- user credential authentication
- token generation
- token authentication
To allow for safe storage of user credentials the password hash is computed using a concatenation of a random string and the user provided password. The salt (the random string) and the hashed password are stored together.
To validate a provided password, the salt and the hashed password are retrieved. Then the hashed password is recomputed using the provided password and the retrieved salt. If the produced hash is equal to the retrieved hashed password, then the provided password is valid.