commit aedc80a5556e84a08166e6723a828a7ea2a19b76 Author: Felix Pankratz Date: Tue Jun 13 15:13:35 2023 +0200 init diff --git a/README.md b/README.md new file mode 100644 index 0000000..2ec235f --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# password generate + +Generate random passwords. Password is written to stdout and copied to the windows clipboard. + +Place both scripts somewhere in your `%PATH%` on Windows, then execute `pw +``` + +e.g. + +``` +./pw.py 32 +``` + + +### vim Shortcut + +``` +let pwcmd = 'cmd.exe /c "python C:\\Tools\\pw.py 10" |tr -d "\\n"|tr -d "\\r"' +:nmap "=system(pwcmd)p +:imap =system(pwcmd) +``` diff --git a/pw.bat b/pw.bat new file mode 100755 index 0000000..774bac9 --- /dev/null +++ b/pw.bat @@ -0,0 +1 @@ +python C:\Tools\pw.py %* diff --git a/pw.py b/pw.py new file mode 100755 index 0000000..dca9472 --- /dev/null +++ b/pw.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import random + +def generate_pw(length): + import string + charset = string.ascii_letters + string.digits + '+-_?!.:,;'; + return ''.join([random.choice(charset) for _ in range(length)]) + +def main(): + import sys + import os + import time + import win32clipboard + if len(sys.argv) > 1: + length = int(sys.argv[1]) + else: + length = 12 + pw = generate_pw(length) + print(pw) + win32clipboard.OpenClipboard() + win32clipboard.EmptyClipboard() + win32clipboard.SetClipboardText(pw, win32clipboard.CF_UNICODETEXT) + win32clipboard.CloseClipboard() + + +if __name__ == '__main__': + main()