[Tutor] Clunky Password maker

ian douglas ian.douglas at iandouglas.com
Thu May 26 23:53:46 CEST 2011


On 05/26/2011 02:45 PM, Wolf Halton wrote:
> Now I am looking at how to make it have an admin function to set the 
> valid characters, and have a way to output the password into main()
>
>

Simple, just learn to use the 'return' statement:

[code]
def new_pass(p):
     pp = int(raw_input("Enter the length you want your password to 
be:[%i] " % (p)) or p)
           # length of password chosen or default length
     new_password = generate_new_pass(pp)
     print "\nYour New Password is: %s\n" % new_password
     return new_password

def generate_new_pass(userlength):
     valchars = string.ascii_letters + string.digits + string.punctuation
     series = list(valchars)
     rr = random.sample(series, userlength)
     return join(rr)

def main():
     my_new_password = new_pass(default_length)
[/code]




More information about the Tutor mailing list