Welcome, guest | Sign In | My Account | Store | Cart

Generates an infinite character pasword

Python, 39 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from random import choice as randomChoice

global passData
global password

passData = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
            '!', '@', '#', '$', '%', '^', '&', '*', '-', '_', '=',
            '+', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ' ']

def newPass():
    while True:
        try:
            passwdNum = int(raw_input("Enter max number of characters: "))
        except TypeError:
            print "Please enter a digit."
            continue
        break        
    gen(passwdNum)

def gen(number):
    password = []
    number = int(number)
    count = 0
    print "\nGenerating password..."
    while count != number:
        password.append(randomChoice(passData))
        count += 1
    x = 0
    p = ''
    while x != len(password):
        p = p + str(password[x])
        x += 1    
    print "Password generated.",
    print "Here's your %s character password. Note that there may be spaces: %s" % (len(password), p)

newPass()

I find this tool very usefull for when I change my passwords every 3 months with online acounts and on my computer.

1 comment

Simon Brunning 18 years, 5 months ago  # | flag

Infinite? Looks pretty finite to me. ;-)

Created by Joseph Quigley on Tue, 11 Oct 2005 (PSF)
Python recipes (4591)
Joseph Quigley's recipes (1)

Required Modules

Other Information and Tasks