Platforms to show: All Mac Windows Linux Cross-Platform

/Util/TOTP


Required plugins for this example: MBS Util Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/TOTP

This example is the version from Tue, 23th May 2022.

Project "TOTP.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control KeyLabel Inherits Label
ControlInstance KeyLabel Inherits Label
End Control
Control KeyField Inherits TextField
ControlInstance KeyField Inherits TextField
EventHandler Sub TextChange() update End EventHandler
End Control
Control TimeNowLabel Inherits Label
ControlInstance TimeNowLabel Inherits Label
End Control
Control TimeNowField Inherits TextField
ControlInstance TimeNowField Inherits TextField
EventHandler Sub TextChange() update End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() TimeNowField.Text = str(CurrentUnixTimeMBS, "-0") End EventHandler
End Control
Control TimeStartLabel Inherits Label
ControlInstance TimeStartLabel Inherits Label
End Control
Control TimeStartField Inherits TextField
ControlInstance TimeStartField Inherits TextField
EventHandler Sub TextChange() update End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() TimeStartField.Text = str(CurrentUnixTimeMBS, "-0") End EventHandler
End Control
Control TimeStepLabel Inherits Label
ControlInstance TimeStepLabel Inherits Label
End Control
Control TimeStepField Inherits TextField
ControlInstance TimeStepField Inherits TextField
EventHandler Sub TextChange() update End EventHandler
End Control
Control DigitCountLabel Inherits Label
ControlInstance DigitCountLabel Inherits Label
End Control
Control DigitCountSlider Inherits Slider
ControlInstance DigitCountSlider Inherits Slider
EventHandler Sub ValueChanged() DigitCountLabel.Text = Str(Me.Value) update End EventHandler
End Control
Control Label6 Inherits Label
ControlInstance Label6 Inherits Label
End Control
Control Label7 Inherits Label
ControlInstance Label7 Inherits Label
End Control
Control TOTPField Inherits TextField
ControlInstance TOTPField Inherits TextField
End Control
Control ValidTimeLabel Inherits Label
ControlInstance ValidTimeLabel Inherits Label
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() TimeNowField.Text = str(CurrentUnixTimeMBS, "-0") update End EventHandler
End Control
EventHandler Sub Open() // test some values Const TimeStep = 30 Dim key As String = "12345678901234567890" Dim t1 As Integer = CalculateTOTPMBS(key, 59, 0, TimeStep, 8) Dim t2 As Integer = CalculateTOTPMBS(key, 1111111109, 0, TimeStep, 8) Dim t3 As Integer = CalculateTOTPMBS(key, 1234567890, 0, TimeStep, 8) System.DebugLog "t1: "+Str(t1) // 94287082 System.DebugLog "t2: "+Str(t2) // 07081804 System.DebugLog "t3: "+Str(t3) // 89005924 // Break TimeNowField.Text = str(CurrentUnixTimeMBS, "-0") update End EventHandler
Sub Update() Dim p As UInt64 = CalculateTOTPMBS(KeyField.Text, TimeNowField.Text.ToInt64, TimeStartField.Text.ToInt64, TimeStepField.Text.ToInt64, DigitCountSlider.Value) TOTPField.Text = Str(p) Dim t As Integer = 30 - (CurrentUnixTimeMBS Mod 30) ValidTimeLabel.Text = "valid for "+Str(t)+" seconds." timer1.Period = t * 1000 + 1000 timer1.Mode = Timer.ModeMultiple End Sub
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

The items on this page are in the following plugins: MBS Util Plugin.


The biggest plugin in space...