Last active
December 30, 2016 07:21
-
-
Save tmiz/e356901962cced5f63365217476d3c91 to your computer and use it in GitHub Desktop.
One time pass word
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
#!/usr/bin/env python | |
import shelve | |
import sys,os | |
import onetimepass as otp | |
def usage(): | |
print "myonetime <domain> <secret> : register secret" | |
print "myonetime <domain> : create one time password" | |
if __name__=="__main__": | |
filename = "/foo/bar/.mysecrets" # * CHANGE HERE * | |
if len(sys.argv) == 1: | |
usage() | |
exit(0); | |
d = shelve.open(filename) | |
if len(sys.argv) == 3: | |
domain = sys.argv[1] | |
secret = sys.argv[2].replace(" ","").upper() | |
d[domain] = secret | |
if len(sys.argv) == 2: | |
domain = sys.argv[1] | |
if (d.has_key(domain)): | |
strValue = "%06d" % otp.get_totp(d[domain]) | |
print "onetime pass: %s" % strValue | |
else: | |
print "does not have secret of domain %s" % domain | |
d.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment