This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/password.py

49 lines
1.4 KiB
Python
Raw Normal View History

# 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
@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-06-11 00:36:29 +02:00
# find the length needed for the password
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
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
if "no caps" not in inp:
okay = okay + list(string.ascii_uppercase)
2012-06-11 00:36:29 +02:00
# add numbers
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
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:
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)
notice(password)