+ 1
I need help with putting my password generator's whole output into a .txt file(on my pc).
https://code.sololearn.com/cJpQisE7dO7G When I try to save those 1000 passwords into a .txt file, it only saves one. I understand that it's because the variable is basically redefined 1000 times so it will save the last one. I'm assuming I have to make it a list of a 1000 created passwords but I don't know how to.
5 Respuestas
+ 5
The code does currently only save the last pw. To write all pws to a file, you need to put them in list. this list is later iterated and writes the items to the file. I have included only a few changes, they are all marked with "# <---" at the end of the code line.
If you run code in playground, be aware to enter all inputs according to the needs of playground.
https://code.sololearn.com/cwGVR9XVmSL6/?ref=app
+ 3
Thank you both so very much! :) It's now fully functional :)
Next step/version probably has to do with unique combinations(like all the possible different combinations for the length between 8-10 from the character list for example). And then sorting that in an alphabetical order :) I feel like that's gonna be hard, but I wanna study cyber security so that could be used as a platform for a dictionary attack :)
+ 2
Working on Lothar's code;
* In the block where you create the passwords, adjust code as follows:
password_list = []
for p in range(Amount):
Password = ''
for c in range(Length):
Password += random.choice(Characters)
password_list.append(Password)
* In the block where you write the file, wdjust code as follows:
file_content = '\n'.join(password_list)
with open(txtfile, "w") as f:
f.write(file_content)
f.close()
(Edited)
+ 1
Good luck with Cyber Security CR34TUR3 👍
+ 1
Thank you :)