TIL (Today I learned) about the python programming language module secrets that can be used to generate random numbers. You can generate random integer below a certain upper bound, say we can generate a number below 200 as follows:
import secretsprint(secrets.randbelow(200))
So how did I come across this? I was looking at how the Hushline (https://hushline.app), a whistleblower platform that provides secure and anonymous tip lines, was handling authentication. They use the secrets module to generate two random numbers for the CAPTCHA math question to verify if a human and not a bot is trying to authenticate. You can look at the code here https://github.com/scidsg/hushline/blob/main/hushline/routes/auth.py#L62. They use the secrets library to generate two random numbers below 10 then add 1 to the numbers that will be displayed to the human to do the math.
Leave a comment