# file: gen.py
import bcrypt
def encrypt_password(username, password):
bcrypted = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt(rounds=12)).decode("utf-8")
return f"{username}:{bcrypted}"
print(encrypt_password("client", "ClientO98"))
$ python gen.py > passwd
$ htpasswd -vb passwd client ClientO98
Password for user client correct.
$ htpasswd -vb passwd client ClientO99
password verification failed
$ htpasswd -vb passwd client1 ClientO98
User client1 not found
Additionally, if you need to replace
2b
or2y
to2a
, you can add this line before returning: