Skip to content

Instantly share code, notes, and snippets.

@shmalex
Created August 24, 2023 09:09
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 shmalex/ec5cc583ac250330bd686e32653b8024 to your computer and use it in GitHub Desktop.
Save shmalex/ec5cc583ac250330bd686e32653b8024 to your computer and use it in GitHub Desktop.
random password generator
import numpy as np
import time
import sys
import argparse as ap
from collections import Counter as cnt
def rule_inrow(psw):
p = ''
for i in psw:
if p == i:
return False
return True
def rule_total(psw, maxx=5):
if max(cnt(psw).values()) > maxx:
return False
return True
def check_pass(psw, checklist):
for cl in checklist:
if cl(psw) == False:
return False
return True
def generate_char():
return chr(np.random.randint(35, 126))
def generate_pass(length=75):
ret = [generate_char()]
while len(ret)< length:
new_char = generate_char()
if check_pass(''.join(ret + [new_char]), [rule_inrow, rule_total]):
ret.append(new_char)
return ret
if __name__ == "__main__":
print(''.join(generate_pass()), flush=True)
sys.stderr.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment