Skip to content

Instantly share code, notes, and snippets.

@hosseinzoda
Last active April 8, 2018 15:49
Show Gist options
  • Select an option

  • Save hosseinzoda/a266e56e790da325ad0d5b734a9e793f to your computer and use it in GitHub Desktop.

Select an option

Save hosseinzoda/a266e56e790da325ad0d5b734a9e793f to your computer and use it in GitHub Desktop.
Get new password!
#!/bin/env /usr/bin/python3
from sys import argv
from os import urandom
from math import floor
def mkpasswd(n, chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-=_+{}|\/?,<>"):
ret = ""
charsn=len(chars)
while n > 0:
index = int(floor((int.from_bytes(urandom(4), byteorder='little', signed=False) / 2**(8*4)) * charsn))
ret += chars[index]
n -= 1
return ret
if len(argv) == 3 and argv[2] == 'simple':
print(mkpasswd(8 if len(argv) < 1 else int(argv[1]), chars="abcdefghijklmnopqrstuvwxyz0123456789"))
elif len(argv) == 3 and argv[2] == 'pin':
print(mkpasswd(8 if len(argv) < 1 else int(argv[1]), chars="0123456789"))
else:
print(mkpasswd(8 if len(argv) < 1 else int(argv[1])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment