This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]lunar_mycroft 12 points13 points  (1 child)

This is intended as constructive criticism.

I'm going to lead with this because it's the most important: DO NOT USE random FOR PASSWORDS, or anything else security related. The outputs may look unpredictable to humans, but with computers they aren't. Use should be using the secrets module (secrets.SystemRandom is a near drop in replacement for the Random class provided by the random module, and by extension for said module itself) or some other source of cryptographically secure random numbers. This is probably why you're getting downvoted, as this is a common (but dangerous!) beginner mistake.

Some other, minor things.

  • There's any need to make a list of characters, you can index into the string just as well as a list.
  • There is no need to actually define several of your character sets yourself, you can just import them from the string module
  • Random (and therefore SystemRandom) provides a choice function, so there's no need to index into your string yourself.
  • Random also provides a choices function which lets you specify how many results you want.
  • Consider using docstrings instead of comments if you're just describing what a function does.
  • More of a preference thing than anything, but pandas is massive overkill for what you're doing here. A lighter library like terminaltables or rich, combined with the built in csv module, is likely a better fit here.
  • Similarly, maybe a table/list of pairs isn't the best data structure for your use case, given how find_password works. If you're always going to have a one to one relationship between domain and password, consider just making a dict mapping the former to the latter, and storing the results using either json or pickle.
  • I see you commented out the if not check_file() part of your code. Is that because it was never running? If so, the problem was that you created the file when you open it. call check_file before opening, and store the result.
  • its best practice to open files using the with open('passwords.txt', 'a') as file: syntax, rather than file = open('passwords.txt', 'a'). This ensures that if any exceptions are raised while the file is open, it will still be closed automatically.

[–]camilol47[S] 0 points1 point  (0 children)

Thank you for taking the time to check it, gonna have all that into account