Skip to content

Instantly share code, notes, and snippets.

@MrMoshkovitz
Created July 29, 2023 13:44
Show Gist options
  • Save MrMoshkovitz/1d84eeb35dda1d79582e0ec3d850ee22 to your computer and use it in GitHub Desktop.
Save MrMoshkovitz/1d84eeb35dda1d79582e0ec3d850ee22 to your computer and use it in GitHub Desktop.
MFA Command Line
#!/usr/bin/python
# MFA Authenticator for the command line
# This script gives a MFA code after 30 seconds from a given Secret key seed (QR code)
# Install pyotp (https://github.com/pyotp/pyotp) and wxPython as:
# pip install pyotp wxpython
# Usage: python mfacode-desktop.py
import sys
import pyotp
import wx
class MyFrame(wx.Frame):
def __init__(self):
super().__init__(parent=None, title='MFA Authenticator')
panel = wx.Panel(self)
my_sizer = wx.BoxSizer(wx.VERTICAL)
self.text_ctrl = wx.TextCtrl(panel)
my_sizer.Add(self.text_ctrl, 0, wx.ALL | wx.EXPAND, 5)
my_btn = wx.Button(panel, label='Generate MFA code')
my_btn.Bind(wx.EVT_BUTTON, self.on_press)
my_sizer.Add(my_btn, 0, wx.ALL | wx.CENTER, 5)
panel.SetSizer(my_sizer)
self.Show()
def on_press(self, event):
value = self.text_ctrl.GetValue()
if not value:
#print("You didn't enter a secret seed!")
wx.MessageBox("You didn't enter a secret seed!", '',
wx.OK | wx.ICON_ERROR)
else:
totp = pyotp.TOTP(value)
dlg = wx.TextEntryDialog(None,"MFA code: ",'',totp.now())
dlg.SetSize((320,180))
if dlg.ShowModal() == wx.ID_OK:
text = dlg.GetValue()
print (text)
dlg.Destroy()
if __name__ == '__main__':
app = wx.App()
frame = MyFrame()
app.MainLoop()
#!/usr/bin/python
# MFA Authenticator for the command line
# This script gives a MFA code after 30 seconds from a given Secret key seed (QR code)
# Install pyotp (https://github.com/pyotp/pyotp) as: pip install pyotp
# Usage: python mfacode.py SEED-HERE
import sys
import pyotp
if __name__ == "__main__":
seed_argument = str(sys.argv[1])
print("Your seed: "+seed_argument)
totp = pyotp.TOTP(seed_argument)
print("MFA code: "+totp.now())

mfa-command-line

MFA Authenticator for the command line.

This script gives a MFA code after 30 seconds from a given Secret key seed (QR code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment