2011-11-20 10:23:31 +01:00
# Password generation code by <TheNoodle>
from util import hook
import string
import random
2012-03-01 21:20:44 +01:00
2011-11-20 10:23:31 +01:00
def gen_password ( types ) :
2012-06-11 00:36:29 +02:00
# Password Generator - The Noodle http://bowlofnoodles.net
2011-11-20 10:23:31 +01:00
okay = [ ]
2012-06-11 00:36:29 +02:00
# find the length needed for the password
2011-11-20 10:23:31 +01:00
numb = types . split ( " " )
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
2011-11-20 10:23:31 +01:00
if " alpha " in types or " letter " in types :
2012-06-11 00:21:44 +02:00
okay = okay + string . ascii_lowercase
2011-11-20 10:23:31 +01:00
#adds capital characters if not told not to
if " no caps " not in types :
2012-06-11 00:21:44 +02:00
okay = okay + string . ascii_uppercase
2012-06-11 00:36:29 +02:00
# add numbers
2011-11-20 10:23:31 +01:00
if " numeric " in types or " numbers " in types :
2012-06-11 00:21:44 +02:00
okay = okay + [ str ( x ) for x in range ( 0 , 10 ) ]
2012-06-11 00:36:29 +02:00
# add symbols
2011-11-20 10:23:31 +01:00
if " symbols " in types :
2012-02-29 09:29:53 +01: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-06-11 00:24:30 +02:00
okay = okay + string . ascii_lowercase
2012-06-11 00:36:29 +02:00
2011-11-20 10:23:31 +01:00
password = " "
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 )
return password
2012-03-01 21:20:44 +01:00
2011-11-20 10:23:31 +01:00
@hook.command
def password ( inp , notice = None ) :
2012-05-16 05:07:27 +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 types, eg. ' numbers symbols ' "
2012-03-01 21:20:44 +01:00
password = gen_password ( inp )
2012-03-01 21:03:27 +01:00
notice ( password )