Send variable from Visual Basic to PHP

0

I am working on a project, where I "read" (with Visual Basic) the serial number of the hard disk of the user's PC, save it in a variable and send it to a php page. I have solved the problem by sending it by the Get method, however, I want to send the data in a more secure way, that is, in which it is not visible to the user. Is there any way to do it? , I would greatly appreciate your help.

The code (in Visual Basic) that I have is the following:

Imports System.Security.Cryptography
Imports System.Text


Public Class Form1

    Function MDhash(ByVal password As String)
        Dim md5 As MD5 = New MD5CryptoServiceProvider()
        Dim result As Byte()
        result = md5.ComputeHash(Encoding.ASCII.GetBytes(password))
        Dim strBuilder As New StringBuilder()
        For i As Integer = 0 To result.Length - 1
            strBuilder.Append(result(i).ToString("x2"))
        Next
        Return strBuilder.ToString()
    End Function


    Private Sub btnSalir_Click(sender As System.Object, e As System.EventArgs) Handles btnSalir.Click
        Dim salir As Integer

        salir = MessageBox.Show("Desea salir", "ADMINISTRADOR", _
           MessageBoxButtons.OKCancel, MessageBoxIcon.Stop)

        If salir = 1 Then
            Close()
        End If
    End Sub


    Private Sub btnIniciar_Click(sender As System.Object, e As System.EventArgs) Handles btnIniciar.Click
        Dim disco As New  _
         System.Management.ManagementObject( _
         "Win32_PhysicalMedia='\.\PHYSICALDRIVE0'") 'Código para saber serial físico del Disco Duro'

        Dim value As String = MDhash(disco.Properties("SerialNumber").Value)
        Process.Start("http://localhost/proyecto/index.php?" & value)
        Me.Close()
    End Sub
End Class
    
asked by Alberto 31.03.2018 в 19:19
source

1 answer

0

Following the suggestion of "alo Malbarez" I was able to adapt the code to make POST requests from Visual Basic to PHP, but the answer is processed by V.B. Is there any way in which the request is processed by PHP, that is, leave the value of the variables in the PHP code of the server?

The code of V.B. it shows me the word "Valido", later it will be another string of characters, the only thing I want is to make it string, the answer in a "MessageBox" does not work for me. How can I adapt the code V.B. to be able to collect, manipulate, and / or compare the answer as a string, instead of showing it to me in a "MessageBox".

This answer throws me if the variable POST sent by VB is compared with the PHP code of the server, what I want is to collect the word "Valid" as a string and be able to manipulate it in V.B.

The code V.B. It is as follows:

Imports System Imports System.Security.Cryptography Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Linq Imports System.Text Imports System.Threading.Tasks Imports System.Windows.Forms Imports System.Net Imports System.IO

Public Class Form1

Function MDhash(ByVal password As String)
    Dim md5 As MD5 = New MD5CryptoServiceProvider()
    Dim result As Byte()
    result = md5.ComputeHash(Encoding.ASCII.GetBytes(password))
    Dim strBuilder As New StringBuilder()
    For i As Integer = 0 To result.Length - 1
        strBuilder.Append(result(i).ToString("x2"))
    Next
    Return strBuilder.ToString()
End Function


Private Sub btnSalir_Click(sender As System.Object, e As System.EventArgs) Handles btnSalir.Click
    Dim salir As Integer

    salir = MessageBox.Show("Desea salir", "Administrador", _
       MessageBoxButtons.OKCancel, MessageBoxIcon.Stop)

    If salir = 1 Then
        Close()
    End If
End Sub


Private Sub btnIniciar_Click(sender As System.Object, e As System.EventArgs) Handles btnIniciar.Click

    Dim disco As New  _
        System.Management.ManagementObject( _
        "Win32_PhysicalMedia='\.\PHYSICALDRIVE0'") 'Código para saber serial físico del Disco Duro'
    Dim value As String = MDhash(disco.Properties("SerialNumber").Value)

    Try

        Dim encoding As ASCIIEncoding = New ASCIIEncoding()
        Dim postData As String = "user=" & value
        Dim data As Byte() = encoding.GetBytes(postData)
        Dim request As WebRequest = WebRequest.Create("http://localhost/proyecto/index.php")
        request.Method = "POST"
        request.ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = data.Length
        Dim stream As Stream = request.GetRequestStream()
        stream.Write(data, 0, data.Length)
        stream.Close()
        Dim response As WebResponse = request.GetResponse()
        stream = response.GetResponseStream()

        Dim respuestaPost As StreamReader = New StreamReader(stream)
        MessageBox.Show(respuestaPost.ReadToEnd())
        respuestaPost.Close()
        stream.Close()

    Catch ex As Exception
        MessageBox.Show("Error : " & ex.Message)
    End Try


    Me.Close()
End Sub

End Class

AND THE PHP CODE IS THE FOLLOWING: Note: The PHP code is coarse, I only use it as an example.

if (isset ($ _ POST ['user']) & & $ _POST ['user'] === "102574") {

echo "Valido"; } else {   echo "Invalid"; }

    
answered by 02.04.2018 в 17:40