Skip to content

Instantly share code, notes, and snippets.

@berviantoleo
Created September 7, 2020 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berviantoleo/f8a356030ca268cc3f8231a94c85c070 to your computer and use it in GitHub Desktop.
Save berviantoleo/f8a356030ca268cc3f8231a94c85c070 to your computer and use it in GitHub Desktop.
Simple Password Generator Python
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