Hello,
this is my first library for Basic4Android, so i am sorry if anything is wrong. I didn't tested everything.
This is a wrapper for this library: https://github.com/wstrange/GoogleAuth
(I had to add the Apache Commons Codec lib too, Which is why it is so big. I will have a look at it to maybe replace it.)
I only needed it to get a TOTP Password from an already existing secret.
But maybe someone else has some other use for it.
I removed the QRCode Stuff, as that was just calling the online service from google, and i think sending security relevant data over the internet is not a super good idea, and we have better QR-Code libraries that should also work offline.
Some small more complete example with a countdown like the google authenticator.
this is my first library for Basic4Android, so i am sorry if anything is wrong. I didn't tested everything.
This is a wrapper for this library: https://github.com/wstrange/GoogleAuth
(I had to add the Apache Commons Codec lib too, Which is why it is so big. I will have a look at it to maybe replace it.)
I only needed it to get a TOTP Password from an already existing secret.
But maybe someone else has some other use for it.
I removed the QRCode Stuff, as that was just calling the online service from google, and i think sending security relevant data over the internet is not a super good idea, and we have better QR-Code libraries that should also work offline.
B4X:
Sub Process_Globals
Private totp As GoogleAuthenticator
End Sub
Dim pass = totp.getTotpPassword("theTOTPsecret")
Some small more complete example with a countdown like the google authenticator.
B4X:
Sub Process_Globals
Private secretKey As String = "JBSWY3DPEHPK3PXP"
Private totp As GoogleAuthenticator
Dim timer1Service As Timer
End Sub
Sub Globals
Private EditText_secret As EditText
Private EditText_totp As EditText
Private EditText_countdown As EditText
End Sub
Sub generateTotp(secret As String)
Dim key As String = ""
Try
key = totp.getTotpPassword(secret)
EditText_totp.Text = key
Catch
EditText_totp.Text = "Invalid Secret"
Log(LastException)
End Try
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
EditText_secret.Text = secretKey
timer1Service.Initialize("timer1Service", 1000)
timer1Service.Enabled = True
generateTotp(secretKey)
End Sub
Sub timer1Service_tick
Dim timewindow As Long = DateTime.Now / 1000.0
Dim countDown As Int = 30 - (timewindow Mod 30)
If timewindow Mod 30 = 0 Then
generateTotp(secretKey)
End If
EditText_countdown.Text = countDown
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub EditText_secret_TextChanged (Old As String, New As String)
secretKey = New
generateTotp(secretKey)
End Sub
Attachments
Last edited: