#Region Project Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
#if B4A
#AdditionalJar: B4XEncryption.jar
#else if B4i
#AdditionalLib: B4XEncryption
#else if B4J
#AdditionalJar: B4XEncryption.jar
#end if
#if B4A
#AdditionalJar: B4XSerializator.jar
#else if B4i
#AdditionalLib: B4XSerializator
#else if B4J
#AdditionalJar: B4XSerializator.jar
#end if
Sub Process_Globals
Private Page As B4XPage
Private edtUsername, edtPassword, edtConfirmPassword, edtVerificationCode As B4XFloatTextField
Private btnRegister, btnSendCode As B4XButton
Private verificationCode As String
End Sub
Public Sub Initialize
Page.Initialize("Page")
Page.Title = "Registration"
Page.RootPanel.LoadLayout("RegistrationLayout")
verificationCode = GenerateVerificationCode
End Sub
Public Sub Show
Page.Show
End Sub
Sub btnRegister_Click
Dim username As String = edtUsername.Text.Trim
Dim password As String = edtPassword.Text
Dim confirmPassword As String = edtConfirmPassword.Text
Dim enteredVerificationCode As String = edtVerificationCode.Text
If username = "" Or password = "" Or confirmPassword = "" Or enteredVerificationCode = "" Then
ToastMessageShow("All fields are required", True)
Return
End If
If password <> confirmPassword Then
ToastMessageShow("Passwords do not match", True)
Return
End If
If enteredVerificationCode <> verificationCode Then
ToastMessageShow("Invalid verification code", True)
Return
End If
Dim encryptedPassword As String = EncryptPassword(password)
End Sub
Sub btnSendCode_Click
verificationCode = GenerateVerificationCode
ToastMessageShow("Verification code sent", True)
End Sub
Private Sub GenerateVerificationCode As String
Dim rnd As Random
rnd.Initialize
Dim code As Int = rnd.Next(1000, 9999)
Return code
End Sub
Private Sub EncryptPassword(password As String) As String
Dim encryptor As B4XCipher
encryptor.Initialize("AES")
encryptor.Password = "YourEncryptionKey"
Return encryptor.EncryptText(password)
End Sub