Random Password Generator
Hello. Does anyone know if there are any built-in Python methods which allow you to generate passwords randomly? Any help would be greatly appreciated. Thanks. -Asad __________________________________________________ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com
On Mon, Feb 17, 2003 at 06:17:30AM -0800, Asad Habib wrote:
Hello. Does anyone know if there are any built-in Python methods which allow you to generate passwords randomly? Any help would be greatly appreciated. Thanks.
not built-in, but this may help : --- CUT --- import os input = os.popen("/usr/bin/makepasswd") clearpassword = input.read().strip() input.close() --- CUT --- bye, Jerome Alet
I use APG: http://www.adel.nursat.kz/apg/ with an external method wrapper around it it's free and has quite a few features, like pronouncable passwords. Asad Habib wrote:
Hello. Does anyone know if there are any built-in Python methods which allow you to generate passwords randomly? Any help would be greatly appreciated. Thanks.
-Asad
__________________________________________________ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
From: "Asad Habib" <ahabib1357@yahoo.com>
Hello. Does anyone know if there are any built-in Python methods which allow you to generate passwords randomly? Any help would be greatly appreciated. Thanks.
-Asad
---------- def generatePassword(self, pwdLen=8): # Returns a random password. import random random.seed() passwd= '' # Since I, 1 ~= l and 0 =~ O, don't generate passwords with them. # This will just confuse people using ugly fonts. charset = 'abcdefghijkmnopqrstuxyzABCDEFGHJKLMNPQRSTUXYZ0123456789' for i in range(pwdLen): passwd = passwd + random.choice(charset) return passwd -------- Add/remove characters from charset if needed. Can probably be re-written as a "Script (Python)". If not use as external method. Cannot vouch for it's non-symmetric-ness (or however that word is spelled, if it even exists, but you get my point... :-) Hop this helps, /dario - -------------------------------------------------------------------- Dario Lopez-Kästen, IT Systems & Services Chalmers University of Tech.
Hi, On Mon, 17 Feb 2003 15:41:17 +0100 Dario Lopez-Kästen <dario@ita.chalmers.se> wrote:
From: "Asad Habib" <ahabib1357@yahoo.com>
Hello. Does anyone know if there are any built-in Python methods which allow you to generate passwords randomly? Any help would be greatly appreciated. Thanks.
-Asad
---------- def generatePassword(self, pwdLen=8): # Returns a random password. import random random.seed() passwd= '' # Since I, 1 ~= l and 0 =~ O, don't generate passwords with them. # This will just confuse people using ugly fonts. charset = 'abcdefghijkmnopqrstuxyzABCDEFGHJKLMNPQRSTUXYZ0123456789' for i in range(pwdLen): passwd = passwd + random.choice(charset) return passwd --------
Thats OK for most cases, but its not really random because it uses a sequence of the pseudo random number generators values. Improvements would be seeding with more then one source (seed() uses time.time() by default) after generating some values and generating variable lenght passwords. ## import random chars=[x for x in 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789+-#!$?'] random.seed() # first seeding from time skip=int(random.random()*8)+1 # random values to skip random.seed(context.REQUEST.channel.creation_time) # another seeding from channel time - hard to guess lengh=int(random.random()*3)+7 # variable lenght of generated password from 7 to 10 chars random.shuffle(chars) random.seed(context.REQUEST.HTTP_USER_AGENT+context.REQUEST.HTTP_ACCEPT_CHARSET+str(DateTime())) random.shuffle(chars) random.seed() # get a fresh seed now return ''.join([random.choice([random.choice(chars) for i in range(skip)]) for o in range(lenght)]) # the above consists of two loops - the inner selects random chars from shuffled big string, "skip" times, the outer selects one char from each loop cycle randomly. # even knowing the channel time, the time, the random number generator internals would it make a challenge to break this password. Ok its not impossible, of course... # the goal was to introduce as much entrophy as possible HTH Tino Wildenhain
On Monday 17 February 2003 4:33 pm, Tino Wildenhain wrote:
the goal was to introduce as much entrophy as possible
On operating systems that support it, reading a few bytes from /dev/urandom is as easy and secure as this approach can get. -- Toby Dickenson http://www.geminidataloggers.com/people/tdickenson
participants (6)
-
Asad Habib -
Ben Avery -
Dario Lopez-Kästen -
Jerome Alet -
Tino Wildenhain -
Toby Dickenson