Python Program Maker is a simple and powerful tool for creating cryptographically strong passwords to secure your data and easily create a nice GUI by combining Python4Delphi and secrets library, inside Delphi and C++Builder. Python4Delphi (P4D) is a free tool that allows you to execute Python scripts, create new Python modules and types in Delphi.
The secrets module is a Python built-in library to generate secure random numbers for managing secrets. The secrets module is used for generating cryptographically strong random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets.
Table of Contents
How can I run the Python secrets library in a Delphi Windows GUI app?
First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.
The secrets module provides functions for generating secure tokens, suitable for applications such as password resets, hard-to-guess URLs, and similar tasks.
To be secure against brute-force attacks, tokens need to have sufficient randomness. Unfortunately, what is considered sufficient will necessarily increase as computers get more powerful and able to make more guesses in a shorter period. In 2015, it is believed that 32 bytes (256 bits) of randomness is sufficient for the typical use-case expected for the secrets module.
How can we generate an eight-character alphanumeric Password, 16-bytes number of token bytes, and hex tokens?
1 2 3 4 5 6 7 8 9 |
import string import secrets alphabet = string.ascii_letters + string.digits password = ''.join(secrets.choice(alphabet) for i in range(8)) print(password) print(secrets.token_bytes(16)) print(secrets.token_hex(16)) |
We execute them many times to show you that all the output are unique, random, and hard to guess:
How can I generate a hard-to-guess temporary URL containing a security token suitable for password recovery applications?
1 2 3 4 |
import secrets url = 'https://pythongui.org/reset=' + secrets.token_urlsafe() print(url) |
We execute them many times to show you that all the output are unique, random, and hard to guess:
Congratulations, now you have learned how to run the secrets library using Python for Delphi to display it in the Delphi Windows GUI app! Now you can solve various real-world cryptographic tasks using the secrets library and Python4Delphi.
The secrets module is a built-in library by Python, so after installing Python, it would be on your system by default. However, you can check out the secrets documentation here: https://docs.python.org/3/library/secrets.html/ and
Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi: https://github.com/pyscripter/python4delphi