HOWTO: Quick password generator with pwgen, python and libnotify
August23
This is a quick snippet to generate random password quickly and also get them copied in your clipboard for fast using.
All you need is python, pwgen, libnotify and pygtk (using GNOME in this one
).
Tested on Debian Lenny.
apt-get install libnotify-bin pwgen
This will install all the necesary files:
The snippet follows:
#!/usr/bin/python
import commands
import subprocess
import pygtk
import gtk
clipboard = gtk.clipboard_get()
# --- Get the password ---
# you can modify the pwgen command to generate different kind of password
# simply run pwgen --help to find out the options.
# This will generate a 10 char password.
word = commands.getoutput("pwgen -1yn 10")
#pasting the password to the clipboard
clipboard.set_text( word )
clipboard.store()
# Displaying the password
subprocess.call(['notify-send', '-u', 'critical', 'Your generated password', word])
You can make the file executable and run it with a double click for quick random password generation.