Initial commt
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
|||||||
|
# Python bytecode & cache
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# Virtual environments
|
||||||
|
.venv/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env/
|
||||||
|
|
||||||
|
# Environment variables & secrets
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
|
||||||
|
# IDE & Editor folders
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Distribution / Packaging
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
*.egg-info/
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
import secrets
|
||||||
|
import string
|
||||||
|
|
||||||
|
# 1. Define your character groups
|
||||||
|
letters = string.ascii_letters
|
||||||
|
digits = string.digits
|
||||||
|
special = "!@#$%^&"
|
||||||
|
|
||||||
|
# 2. Combine all characters for the "pool"
|
||||||
|
all_characters = letters + digits + special
|
||||||
|
|
||||||
|
# 3. Start the password with one guaranteed character from each group
|
||||||
|
password_list = [
|
||||||
|
secrets.choice(letters),
|
||||||
|
secrets.choice(digits),
|
||||||
|
secrets.choice(special)
|
||||||
|
]
|
||||||
|
|
||||||
|
# 4. Fill the remaining length (16 - 3 = 13 characters) from the full pool
|
||||||
|
password_list += [secrets.choice(all_characters) for _ in range(13)]
|
||||||
|
|
||||||
|
# 5. Shuffle the list so the guaranteed characters aren't always at the start
|
||||||
|
# We use secrets.SystemRandom() to ensure the shuffle is cryptographically secure
|
||||||
|
secrets.SystemRandom().shuffle(password_list)
|
||||||
|
|
||||||
|
# 6. Join into a single string
|
||||||
|
password = "".join(password_list)
|
||||||
|
|
||||||
|
print(password)
|
||||||
Reference in New Issue
Block a user