hashlib provides Python’s standard-library hashing algorithms for turning input into values that are difficult to read or recover. Hashes support password checks and tamper detection without storing the original password. section 7.5.1
The practical rules are:
- Prefer scrypt for password hashing because it uses a salt and resists straightforward recovery and brute-force attacks better than plain SHA choices. section 7.5.1
- Consider multithreading for large hashing workloads: many hashlib operations release the GIL above 2048 bytes, while scrypt always releases it. section 7.5 section 7.5.1
Hashing passwords with scrypt
Generate a random salt with os.urandom(16), then call hashlib.scrypt(password, salt=salt, n=2048, p=1, r=8). A synchronous loop hashes 10,000 generated passwords; a threaded asyncio version submits the same work to a ThreadPoolExecutor and awaits it with asyncio.gather.

