Created
September 7, 2020 00:52
-
-
Save berviantoleo/f8a356030ca268cc3f8231a94c85c070 to your computer and use it in GitHub Desktop.
Simple Password Generator Python
This file contains 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
import string | |
import secrets | |
import sys | |
alphabet = string.ascii_letters + string.digits | |
def generatePass(): | |
while True: | |
password = ''.join(secrets.choice(alphabet) for i in range(10)) | |
if (any(c.islower() for c in password) | |
and any(c.isupper() for c in password) | |
and sum(c.isdigit() for c in password) >= 3): | |
return password | |
def main(total_number): | |
with open("pass-list.txt", "w") as f: | |
for i in range(total_number): | |
f.write(generatePass()) | |
f.write("\n") | |
if __name__ == '__main__': | |
arg_num = len(sys.argv) | |
if (arg_num == 2): | |
total_number = int(sys.argv[1]) | |
main(total_number) | |
elif (arg_num == 1): | |
main(1000) | |
else: | |
print('Please run with argument or not have any argument, example "python pass-gen.py" or "python pass-gen.py 1000" without double quote.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment