generating random passwords ... for a csv file with user details

Discussion in 'Python' started by k.i.n.g., May 28, 2006.

  1. k.i.n.g.

    k.i.n.g. Guest


    I have a csv file which in taken as the input file for adding users in
    my linux mail server with the format


    Now I have to write a script to generate random password in the
    password field for each user. A simple algorithm is sufficient for

    I being new to scripting would seek all your help in doing so

    Thanks In advance

    k.i.n.g., May 28, 2006
    1. Advertisements

  2. import random

    def rand_str(len):
    chars = ''.join(['abcdefghijklmnopqrstuvwxyz',
    '_+']) # plus whatever additional characters you
    return ''.join([random.choice(chars) for i in range(len)])

    print rand_str(10)
    andychambers2002, May 28, 2006
    1. Advertisements

  3. Kanthi skrev:

    Klaus Alexander Seistrup, May 28, 2006
  4. k.i.n.g. enlightened us with:
    Check out the source of pwsafe, it has a great password generator. It
    can generate with different lengths, based on amount of entropy, and
    can also generate different types (alpha/digit, hex, easy to read
    alpha/digit, etc.)

    Sybren Stuvel, May 28, 2006
  5. k.i.n.g.

    k.i.n.g. Guest

    Hi ALL,

    I am sorry for not mentioning that I am new to python and scripting.
    How can I add the above script to handle csv file. I want the script to
    generate passwords in the passwords column/row in a csv file.


    The script should read the userid and genrate the password for each
    user id (there are thousands of userids)

    k.i.n.g., May 29, 2006
  6. k.i.n.g.

    Jon Clements Guest

    Something like:

    import csv
    in_csv=csv.reader( file('your INPUT filenamehere.csv') )
    out_csv=csv.writer( file('your OUPUT filenamehere.csv','wb') )
    ## If you have a header record on your input file, then
    out_csv.writerow( )
    ## Iterate over your input file
    for row in in_csv:
    # Row will be a list where row[0]=userid and row[3]=passwd
    # Assuming you want to write password as new field then
    out_csv.writerow( row + [password] )
    # Assuming you want to over-write password field then
    row[3] = password

    All the best,

    Jon Clements, May 29, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.