samedi 9 février 2019

Python- How to fix loop in random password generator to fill row in csv file with new random password each line

I would like to ask for help with this code. I have a csv file with 3 rows: name, email, password (same password each column) and I would like to change that password to random password generated from my program. It works, but it fills same password each column, and I would like to change that to different random password each column.

import pandas as pd
import string
from random import *
def fu():
    characters = string.ascii_letters + string.digits
    password =  "".join(choice(characters) for x in range(randint(6, 8)))
    while password:
        characters = string.ascii_letters + string.digits
        password =  "".join(choice(characters) for x in range(randint(6, 8)))
        return(password)



df = pd.read_csv("login.csv")
df.head(3)
x =  fu()
df.loc[df["password"]=="mediasys", "password"] = x

df.to_csv("test.csv", index=False)

it looks like this: name,email,password:
a,a@a.com,abc/ b, b@b.com,abc

and I would like something like this: name,email,password:
a,a@a.com,abc/ b,b@b.com,acb ... thanks




Aucun commentaire:

Enregistrer un commentaire