B4J Question Compare text from WebView

klingon467

Member
Licensed User
Longtime User
Hi,
I need to adapt this vb6 routine from B4J
i want to compare text from url into webview

source vb6:

B4X:
Private Sub CommandSend_Click()
   Dim testo As String, p As Integer, cerca As String, I As Integer
   Dim min As Integer, max As Integer
 
With WebBrowser1
.Silent = True
.Navigate "http://kerberos5.net63.net/hwid/hwid/HID3.php?id=" & Text1.Text
Do
         DoEvents
      Loop Until fine
      testo = .Document.body.innertext  'here's' the entire web page in the form of plain text...
     End With
cerca = "OK"
If Left$(testo, 2) = cerca Then  'I compare the message coming from WebBrowser
        'MsgBox ("Done!"), vbInformation 'call my certificate function
    Call crtlcert
          Else
        'MsgBox ("Invalid HWID!, please enter the correct code and try again")
           End If
 End Sub

thanks
 

klingon467

Member
Licensed User
Longtime User
Use jHttpUtils2 to download the text and then compare it.
Thanks @Erel work fine....
Now I would like to activate a button or menu after comparing the string obtained but can not activate the button...
menu_action the event off and reactivated after check but remains inactive
???

B4X:
Sub mLogin_Action 'menù action
frmLogin.show 'load form
imgLogo.SetImage(fx.LoadImage(File.DirAssets, "denied.png"))
Dim ivLog1 As ImageView 'reset
ivLog1.Initialize("")
ivLog1.SetImage(fx.LoadImage(File.DirAssets, "load.png"))
SetGraphic(btnLoad, ivLog1)

Dim ivLog2 As ImageView 'reset
ivLog2.Initialize("")
ivLog2.SetImage(fx.LoadImage(File.DirAssets, "key.png"))
SetGraphic(btnLogin, ivLog2)
btnLogin.Enabled = False 'disable button on load form

End Sub
Sub btnLogin_Action
       
    If txtAuth.Text.Contains("OK") Then
        btnLogin.Enabled = True 'if string compare enable button
        Log("OK")
        Else
        Log("Permission denied!")
    End If
   
End Sub
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Looks like you are trying to enable the button inside the routine that can not get called because you disabled the button.
You need to enable the button outside of the btnLogin_Action sub otherwise the code inside it can not execute.
 
Upvote 0

klingon467

Member
Licensed User
Longtime User
ok! i share my code for authentication from b4j to web ;)
first control HWID generated
second control password checked by file on web server encrypted in Base64

add-ons:
HttpUtils2Service.bas
HttpJob.bas

libraries:

jHTTP
jStringUtils

components:
Private frmLogin As Form
Private txtPwdLogin As TextField
Private hwidLogin As TextField
Private txtAuth As TextField
Private imgLogo As ImageView
Private btnLoad As Button
Dim btnLogin As Button
Private chkSave As CheckBox
Private mCon As MenuItem
Private mDisc As MenuItem
Private btnLogHide As Button
Private lblLogStatus As Label
Dim txtCert As String
Dim su As StringUtils

B4X:
#Region ------------- Login Form -----------------------

Sub mLogin_Action 'menù action
frmLogin.show 'load form
imgLogo.SetImage(fx.LoadImage(File.DirAssets, "lucClose.png"))
Dim ivLog1 As ImageView 'reset
ivLog1.Initialize("")
ivLog1.SetImage(fx.LoadImage(File.DirAssets, "load.png"))
SetGraphic(btnLoad, ivLog1)

Dim ivLog2 As ImageView 'reset
ivLog2.Initialize("")
ivLog2.SetImage(fx.LoadImage(File.DirAssets, "key.png"))
SetGraphic(btnLogin, ivLog2)

Dim ivLogH As ImageView 'reset
ivLogH.Initialize("")
ivLogH.SetImage(fx.LoadImage(File.DirAssets, "quit.png"))
SetGraphic(btnLogHide, ivLogH)

chkSave.Checked = False

If File.Exists(File.DirApp, "passwd.ini") Then
    Dim strAll As String
strAll = File.ReadString(File.DirApp, "passwd.ini")
Dim seg() As String
        seg = Regex.Split( "SPLT", strAll)
        hwidLogin.Text = seg(0)
        txtPwdLogin.Text = seg(1)
End If

End Sub
Sub btnLogin_Action
      
    If txtAuth.Text.Contains("OK") Then
        crtlhwid
        Else
        lblLogStatus.text = "Permission denied!"
    End If
  
End Sub

Sub btnLoad_Action
    Try
    Dim job1, job2, job3, job4 As HttpJob
    job1.Initialize("Job1", Me)
    job2.Initialize("Job2", Me)
    job2.Download("http://kerberos5.net63.net/hwid/hwid/HID3.php?id=" & hwidLogin.Text)
    job3.Initialize("Job3", Me)
    job3.Download("http://kerberos5.net63.net/hwid/hwid/lucOpen.png")
    job4.Initialize("Job4", Me)
    job4.Download("http://kerberos5.net63.net/hwid/" & hwidLogin.Text & ".cer")
    Catch
    Msgbox.Show(LastException.Message, "RAT4A")
    End Try

End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "Job1", "Job2"
                'print the result to the logs
                'Log(Job.GetString)
                txtAuth.Text = Job.GetString
            Case "Job3"
                'show the downloaded image
                imgLogo.SetImage(Job.GetBitmap)
                lblLogStatus.text = "HWID checked!"
            Case "Job4"
                txtCert = Job.GetString
            End Select
    Else
        Log("Error: " & Job.ErrorMessage)
    End If
    Job.Release
  
End Sub
Sub chkSave_CheckedChange(Checked As Boolean)
    If chkSave.Checked = True Then
        File.WriteString(File.DirApp, "passwd.ini", hwidLogin.Text & "SPLT" & txtPwdLogin.Text)
        Msgbox.Show("Saved!", "RAT4A")
        End If
  
End Sub

Sub btnLogHide_Action
    frmLogin.close
End Sub

Sub crtlhwid()
    Dim bb1(), bb2(), bb3() As Byte
    Dim seg() As String
        seg = Regex.Split( "##@@##", txtCert)
bb1 = su.DecodeBase64(seg(0))
bb2 = su.DecodeBase64(seg(1))
bb3 = su.DecodeBase64(seg(2))
Dim section1 As String
Dim section2 As String
Dim section3 As String
        section1 = BytesToString(bb1, 0, bb1.Length, "UTF8")
        Log("Username: " & section1)
        section2 = BytesToString(bb2, 0, bb2.Length, "UTF8")
        Log("HWID: " & section2)
        section3 = BytesToString(bb3, 0, bb3.Length, "UTF8")
        Log("Password: " & section3)
If txtPwdLogin.Text = section3 Then
mCon.Enabled = True
mDisc.Enabled = True
Msgbox.Show("Welcome: " & section1, "RAT4A")
Else
Msgbox.Show("Incorrect Password!", "RAT4A")
End If
End Sub
#End Region

on your web server: HID3.php
B4X:
<?php

if ($_GET['id'] != ''){
    $puntero = fopen('HID3.txt', 'r');
    while(!feof($puntero)){
        $base = explode('|', fgets($puntero));
                if($base[0] == $_GET['id']){
            fclose($puntero);
            $checksum = 0;
            for ($i=24; $i<35; $i++) {
                $checksum += $_GET['id']{$i} * $i;
            }
            echo 'OK|'.'User: '.$base[1].'|'.'Expiration date: '.$base[3];
            exit;
        }
    }
    fclose($puntero);
    echo "Permission denied!";
}else{
    echo "Permission denied!";
}

?>

auth.png
 
Upvote 0
Top