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

K

k.i.n.g.

Hi,

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

userid,fullname,passwword,dateofbith

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

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

Thanks In advance

kanthi
 
A

andychambers2002

import random

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

print rand_str(10)
 
K

Klaus Alexander Seistrup

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

userid,fullname,passwword,dateofbith

Now I have to write a script to generate random password in the
password field for each user. A simple algorithm is sufficient
for passwords
#v+
import sha
sha.sha('userid,fullname,passwword,dateofbith').digest().encode('base64')[:10] 'q0nCDQ1YdL'

#v-

Mvh,
 
S

Sybren Stuvel

k.i.n.g. enlightened us with:
Now I have to write a script to generate random password in the
password field for each user. A simple algorithm is sufficient for
passwords

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
 
K

k.i.n.g.

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.

userid,realname,dateofB,passwd

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

Kanthi
 
J

Jon Clements

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( in_csv.next() )
## Iterate over your input file
for row in in_csv:
# Row will be a list where row[0]=userid and row[3]=passwd
password=some_function_as_advised_by_rest_of_group()
# 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
out_csv.writerow(row)

All the best,

Jon.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top