2012-09-04 12:38:54 +02:00
|
|
|
# based on password generation code by TheNoodle
|
2011-11-20 10:23:31 +01:00
|
|
|
from util import hook
|
|
|
|
import string
|
|
|
|
import random
|
|
|
|
|
2012-03-01 21:20:44 +01:00
|
|
|
|
2012-09-04 12:38:54 +02:00
|
|
|
@hook.command
|
|
|
|
def password(inp, notice=None):
|
2013-09-04 12:30:04 +02:00
|
|
|
"""password <length> [types] -- Generates a password of <length> (default 10).
|
|
|
|
[types] can include 'alpha', 'no caps', 'numeric', 'symbols' or any combination of the inp, eg. 'numbers symbols'"""
|
2011-11-20 10:23:31 +01:00
|
|
|
okay = []
|
2012-09-04 12:38:54 +02:00
|
|
|
|
2012-06-11 00:36:29 +02:00
|
|
|
# find the length needed for the password
|
2012-09-04 12:38:54 +02:00
|
|
|
numb = inp.split(" ")
|
2012-10-12 01:23:37 +02:00
|
|
|
|
2012-06-11 00:21:44 +02:00
|
|
|
try:
|
|
|
|
length = int(numb[0])
|
|
|
|
except ValueError:
|
|
|
|
length = 10
|
2012-06-11 00:36:29 +02:00
|
|
|
|
|
|
|
# add alpha characters
|
2012-09-04 12:38:54 +02:00
|
|
|
if "alpha" in inp or "letter" in inp:
|
|
|
|
okay = okay + list(string.ascii_lowercase)
|
2011-11-20 10:23:31 +01:00
|
|
|
#adds capital characters if not told not to
|
2012-09-04 12:38:54 +02:00
|
|
|
if "no caps" not in inp:
|
|
|
|
okay = okay + list(string.ascii_uppercase)
|
2012-06-11 00:36:29 +02:00
|
|
|
|
|
|
|
# add numbers
|
2012-09-04 12:38:54 +02:00
|
|
|
if "numeric" in inp or "number" in inp:
|
|
|
|
okay = okay + [str(x) for x in xrange(0, 10)]
|
2012-06-11 00:36:29 +02:00
|
|
|
|
|
|
|
# add symbols
|
2012-09-04 12:38:54 +02:00
|
|
|
if "symbol" in inp:
|
2013-09-04 12:30:04 +02:00
|
|
|
sym = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', '_', '+', '[', ']', '{', '}', '\\', '|', ';',
|
|
|
|
':', "'", '.', '>', ',', '<', '/', '?', '`', '~', '"']
|
2012-06-11 00:36:29 +02:00
|
|
|
okay += okay + sym
|
|
|
|
|
|
|
|
# defaults to lowercase alpha password if the okay list is empty
|
|
|
|
if not okay:
|
2012-09-04 12:38:54 +02:00
|
|
|
okay = okay + list(string.ascii_lowercase)
|
2012-06-11 00:36:29 +02:00
|
|
|
|
2011-11-20 10:23:31 +01:00
|
|
|
password = ""
|
2012-10-12 01:23:37 +02:00
|
|
|
|
2012-06-11 00:36:29 +02:00
|
|
|
# generates password
|
2011-11-20 10:23:31 +01:00
|
|
|
for x in range(length):
|
|
|
|
password = password + random.choice(okay)
|
|
|
|
|
2012-03-01 21:03:27 +01:00
|
|
|
notice(password)
|