Python · Paste
Random Password
Pastes a strong random password into the app in front. Defaults to 20 characters; enter a length from 8 to 128.
- Language
- Python
- Output
- Paste
- Keyword
pw- Arguments
- Length (optional) (optional)
- Licence
- MIT
- Author
- Docktopus
- File
- random-password.py (1.1 KB)
- Downloads
- 0
In Docktopus: Settings → Scripts → Browse Community Scripts. Read the source before you run any script.
Source
random-password.py · sha256 c2facfae3b12…#!/usr/bin/env python3
# @docktopus.schemaVersion 1
# @docktopus.title Random Password
# @docktopus.mode paste
# @docktopus.icon key
# @docktopus.keyword pw
# @docktopus.description Pastes a strong random password into the app in front. Defaults to 20 characters; enter a length from 8 to 128.
# @docktopus.argument1 {"type": "text", "placeholder": "Length (optional)", "optional": true}
# @docktopus.author Docktopus
import secrets
import string
import sys
raw = sys.argv[1].strip() if len(sys.argv) > 1 else ""
length = int(raw) if raw.isdigit() else 20
if not 8 <= length <= 128:
sys.exit("Choose a length from 8 to 128.")
# Leave out characters that are easy to confuse when read aloud or typed by hand.
letters = "".join(ch for ch in string.ascii_letters if ch not in "lIO")
digits = "23456789"
symbols = "-_.!@#%+="
alphabet = letters + digits + symbols
while True:
password = "".join(secrets.choice(alphabet) for _ in range(length))
if (any(ch.islower() for ch in password) and any(ch.isupper() for ch in password)
and any(ch in digits for ch in password) and any(ch in symbols for ch in password)):
break
print(password, end="")