Last active
October 2, 2023 21:35
-
-
Save talbii/83ac4aaa6d6ed975a368fd9282ddd307 to your computer and use it in GitHub Desktop.
I keep seeing "password generator in Python" videos/comments which are written horribly, so I've decided to write a decent one instead. *Not cryptographically secure.*
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from random import choices | |
| #from secrets import choice # cryptographically secure version: | |
| #choices = lambda N : [choice(letters) for _ in range(N)] | |
| import string | |
| letters = string.ascii_letters + string.digits + string.punctuation | |
| password_gen = lambda N : ''.join(choices(letters, k=N)) | |
| if __name__ == '__main__': | |
| n = int(input("Enter a positive integer: ")) | |
| print(password_gen(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment