1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Sign Up With Captcha

Discussion in 'Visual Basic .NET' started by v7web, Oct 11, 2011.

  1. v7web

    v7web Registered Member

    Joined:
    Jul 15, 2010
    Messages:
    51
    Likes Received:
    3
    Hi,
    Has anyone got a working application in vb.net to sign up to a website using deathbycaptcha?
    Doesn't matter what site it is I just need an example I can work from, you know what its like, it is easier to learn using working examples.

    Many thanks
     
  2. christoss1959

    christoss1959 Senior Member

    Joined:
    Nov 25, 2010
    Messages:
    894
    Likes Received:
    1,150
    Home Page:
    If you know how to create a form filler then the rest should be pretty basic since they have a .NET API you can use. There is also an example in their website:
    Code:
    http://www.deathbycaptcha.com/user/api
     
  3. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    Have they got a HTTP API? If so below is a VB.NET example for Decaptcher.com which I am sure can be easily ammended for DBC.

    Code:
    Imports System
    Imports System.Text
    Imports System.IO
    Imports System.Net
    
    Namespace TBNDecaptcher
        Class Decaptcher
    
            Private username As String = My.Settings.DecaptcherUser
            Private password As String = My.Settings.DecaptcherPass
    
            Private resultCode As String = ""
            Private majorId As String = ""
            Private minorId As String = ""
            Private type As String = ""
            Private timeout As String = ""
    
            Public Function PostCaptcha(ByVal FilePath As String) As String
                Dim captcha As System.Drawing.Image
                Dim fs As New System.IO.FileStream(FilePath, System.IO.FileMode.Open)
                captcha = Image.FromStream(fs)
    
                Dim captchaResponse As String = ""
                Dim boundary As String = "myBoundary"
                Dim builder As New StringBuilder()
    
                builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""function""")
                builder.Append(vbCr & vbLf & vbCr & vbLf)
                builder.Append("picture2")
                builder.Append(vbCr & vbLf)
    
                builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""username""")
                builder.Append(vbCr & vbLf & vbCr & vbLf)
                builder.Append(username)
                builder.Append(vbCr & vbLf)
    
                builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""password""")
                builder.Append(vbCr & vbLf & vbCr & vbLf)
                builder.Append(password)
                builder.Append(vbCr & vbLf)
    
                builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""pict_to""")
                builder.Append(vbCr & vbLf & vbCr & vbLf)
                builder.Append("0")
                builder.Append(vbCr & vbLf)
    
                builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""pict_type""")
                builder.Append(vbCr & vbLf & vbCr & vbLf)
                builder.Append("0")
                builder.Append(vbCr & vbLf)
    
                builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""pict""; filename=captcha.jpg")
                builder.Append(vbCr & vbLf)
                builder.Append("Content-Type: image/jpeg")
                builder.Append(vbCr & vbLf & vbCr & vbLf)
    
                Dim headerBytes As Byte() = Encoding.ASCII.GetBytes(builder.ToString())
    
                Dim ms As New MemoryStream()
                captcha.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
    
                Dim imageBytes As Byte() = ms.ToArray()
    
                Dim footerBytes As Byte() = Encoding.ASCII.GetBytes((vbCr & vbLf & "--") + boundary)
    
                Dim postBytes As Byte() = New Byte(headerBytes.Length + imageBytes.Length + (footerBytes.Length - 1)) {}
    
                Buffer.BlockCopy(headerBytes, 0, postBytes, 0, headerBytes.Length)
                Buffer.BlockCopy(imageBytes, 0, postBytes, headerBytes.Length, imageBytes.Length)
                Buffer.BlockCopy(footerBytes, 0, postBytes, headerBytes.Length + imageBytes.Length, footerBytes.Length)
    
                Try
                    Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://decaptcher.com/poster/"), HttpWebRequest)
                    req.Method = "POST"
                    req.ContentType = "multipart/form-data; boundary=" & boundary
                    req.ContentLength = postBytes.Length
                    req.ServicePoint.Expect100Continue = False
    
                    Using reqStream As Stream = req.GetRequestStream()
                        reqStream.Write(postBytes, 0, postBytes.Length)
                    End Using
                    Using resp As WebResponse = req.GetResponse()
                        Using respStream As Stream = resp.GetResponseStream()
                            Using read As New StreamReader(respStream)
                                captchaResponse = read.ReadToEnd()
                            End Using
                        End Using
                    End Using
    
                    Dim respValues As String() = captchaResponse.Split("|"c)
                    resultCode = respValues(0)
                    majorId = respValues(1)
                    minorId = respValues(2)
                    type = respValues(3)
                    timeout = respValues(4)
                    captchaResponse = respValues(5)
                    fs.Close()
                    Return captchaResponse
                Catch
                    Return captchaResponse
                End Try
    
            End Function
    
            Public Sub BadCaptcha()
                Dim boundary As String = "myBoundary"
    
                Dim builder As New StringBuilder()
    
                builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""function""")
                builder.Append(vbCr & vbLf & vbCr & vbLf)
                builder.Append("picture_bad2")
                builder.Append(vbCr & vbLf)
    
                builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""username""")
                builder.Append(vbCr & vbLf & vbCr & vbLf)
                builder.Append(username)
                builder.Append(vbCr & vbLf)
    
                builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""password""")
                builder.Append(vbCr & vbLf & vbCr & vbLf)
                builder.Append(password)
                builder.Append(vbCr & vbLf)
    
                builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""major_id""")
                builder.Append(vbCr & vbLf & vbCr & vbLf)
                builder.Append(majorId)
                builder.Append(vbCr & vbLf)
    
                builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""minor_id""")
                builder.Append(vbCr & vbLf & vbCr & vbLf)
                builder.Append(minorId)
                builder.Append(vbCr & vbLf)
    
                builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""submit""")
                builder.Append(vbCr & vbLf & vbCr & vbLf)
                builder.Append("Send")
                builder.Append(vbCr & vbLf)
                builder.Append("--" & boundary)
    
                Dim postString As String = builder.ToString()
    
                Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://poster.decaptcher.com/"), HttpWebRequest)
                req.Method = "POST"
                req.ContentType = "multipart/form-data; boundary=" & boundary
                Using reqStream As Stream = req.GetRequestStream()
                    reqStream.Write(Encoding.ASCII.GetBytes(postString), 0, postString.Length)
                End Using
                Using resp As WebResponse = req.GetResponse()
                    Using respStream As Stream = resp.GetResponseStream()
                        Using read As New StreamReader(respStream)
                            Dim result As String = read.ReadToEnd()
                        End Using
                    End Using
                End Using
            End Sub
        End Class
    End Namespace