469,134 Members | 1,315 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,134 developers. It's quick & easy.

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

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

May 28 '06 #1
5 3697
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)

May 28 '06 #2
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').di gest().encode('base64')[:10] 'q0nCDQ1YdL'


#v-

Mvh,

--
Klaus Alexander Seistrup
SubZeroNet, Copenhagen, Denmark
http://magnetic-ink.dk/
May 28 '06 #3
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
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
May 28 '06 #4
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

May 29 '06 #5
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.

k.i.n.g. wrote:
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


May 29 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Peter Fox | last post: by
3 posts views Thread by John Buchmann | last post: by
2 posts views Thread by Simon Wittber | last post: by
19 posts views Thread by Cord-Heinrich Pahlmann | last post: by
3 posts views Thread by John | last post: by
2 posts views Thread by Simon.Whiteside | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.