Python. Двухфакторная авторизация через Google Authenticator » комментарииhttps://adw0rd.com/2014/10/01/tfa-totp-google-authenticator/2019-07-26T08:04:06.599432+03:00Блог Михаила Андреева, ака adw0rdБорис на "Python. Двухфакторная авторизация через Google Authenticator"
2019-07-26T08:04:06.599432+03:00Борисhttps://adw0rd.com/2014/10/01/tfa-totp-google-authenticator/#comment-6599Я для себя написал следующий код: import hmac, base64, struct, hashlib, time, os def clearShell(): os.system(['cls'][os.name == os.sys.platform]) def HOTP(secret, intervals_no): key = base64.b32decode(secret, True) msg = struct.pack(">Q", intervals_no) h = hmac.new(key, msg, hashlib.sha1).digest() o = h[19] & 15 h = (struct.unpack(">I", h[o:o+4])[0] & 0x7fffffff) % 1000000 return h def…
<p>Я для себя написал следующий код:</p>
<pre><code>import hmac, base64, struct, hashlib, time, os
def clearShell():
os.system(['cls'][os.name == os.sys.platform])
def HOTP(secret, intervals_no):
key = base64.b32decode(secret, True)
msg = struct.pack(">Q", intervals_no)
h = hmac.new(key, msg, hashlib.sha1).digest()
o = h[19] & 15
h = (struct.unpack(">I", h[o:o+4])[0] & 0x7fffffff) % 1000000
return h
def TOTP(secret):
return HOTP(secret, intervals_no=int(time.time())//30)
S = {
'Название': 'YOURSECRETCODE01',
'Название': 'YOURSECRETCODE02'
}
lenght = 17 # Максимальная длина названия
line = ""
for i in range(0, lenght+18):
line += "-"
line += "\n"
while True:
text = line
t = 30 - (int(time.time()) % 30)
i = 0
for s in S:
i = i + 1
code = TOTP(S[s])
c1 = str(code//1000).rjust(3, '0')
c2 = str(code %1000).rjust(3, '0')
code = c1 + " " + c2
text += "| " + str(i).ljust(3, ' ') + " " + \
s.ljust(lenght, ' ') + " " + code + " |\n" + line
text += "\n ( " + str(t) + " с. )"
clearShell()
print(text)
time.sleep(1)
</code></pre>
adw0rd на "Python. Двухфакторная авторизация через Google Authenticator"
2014-10-04T16:06:59+04:00adw0rdhttps://adw0rd.com/2014/10/01/tfa-totp-google-authenticator/#comment-6400Да, для джанги уже куча таких либ, я уже решил ничего не писать https://github.com/Bouke/django-two-factor-auth https://github.com/mtigas/django-twofactor
<p>Да, для джанги уже куча таких либ, я уже решил ничего не писать</p>
<p>https://github.com/Bouke/django-two-factor-auth<br />
https://github.com/mtigas/django-twofactor</p>
Илья на "Python. Двухфакторная авторизация через Google Authenticator"
2014-10-04T11:13:50+04:00Ильяhttps://adw0rd.com/2014/10/01/tfa-totp-google-authenticator/#comment-6399Есть для джанги уже django-secureauth
<p>Есть для джанги уже django-secureauth </p>