Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A simple password generator written while reflecting on an Espanso Hub submission
- # Called by `:genpass()` for a twelve-character password, or
- # `:genpass(n)` for an n-length password.
- # The script will add the result to the clipboard for pasting elsewhere,
- # if `pyperclip` is installed
- - regex: :genpass\((?P<myvar>\d*)\)
- replace: "{{output}}"
- vars:
- - name: output
- type: script
- params:
- args:
- - python
- - -c
- - |
- import random, string
- characters = string.ascii_letters + string.punctuation + string.digits
- n = max(4, int('{{myvar}}') if '{{myvar}}'.isdigit() else 12)
- while True:
- password = ''.join(random.choice(characters) for _ in range(n))
- if (any(c.islower() for c in password) and any(c.isupper() for c in password) and any(c in string.punctuation for c in password) and any(c.isdigit() for c in password)):
- break
- try:
- import pyperclip
- pyperclip.copy(password)
- except:
- pass
- print(password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement