Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private cookies As New CookieContainer
- Dim csrftoken As String = ""
- Dim mid As String = ""
- Dim sessionid As String = ""
- Dim ig_dau_dismiss As String = ""
- Dim ds_user_id As String = ""
- Dim cooks As String = ""
- Private Function login(ByVal user As String, ByVal pass As String) As String
- Dim result As String
- Try
- Dim RequestGET As HttpWebRequest = DirectCast(WebRequest.Create("https://www.instagram.com"), HttpWebRequest)
- RequestGET.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:58.0) Gecko/20100101 Firefox/58.0"
- RequestGET.Method = "GET"
- RequestGET.CookieContainer = New CookieContainer
- RequestGET.KeepAlive = True
- Dim ResponseGET As HttpWebResponse = DirectCast(RequestGET.GetResponse(), HttpWebResponse)
- For Each cook As Cookie In ResponseGET.Cookies
- If cook.Name = "csrftoken" Then
- csrftoken = cook.Value
- End If
- If cook.Name = "mid" Then
- mid = cook.Value
- End If
- Next
- cooks += "mid=" + mid + ";csrftoken=" + csrftoken
- RequestGET.Abort()
- ResponseGET.Close()
- Dim RequestPOST As HttpWebRequest = DirectCast(WebRequest.Create("https://www.instagram.com/accounts/login/ajax/"), HttpWebRequest)
- RequestPOST.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:58.0) Gecko/20100101 Firefox/58.0"
- RequestPOST.Method = "POST"
- RequestPOST.Timeout = 5000
- RequestPOST.Referer = "https://www.instagram.com/"
- RequestPOST.Headers.Add("X-CSRFToken", csrftoken)
- RequestPOST.Headers.Add("Cookie", cooks)
- RequestPOST.ContentType = "application/x-www-form-urlencoded"
- Dim data As Byte() = Encoding.UTF8.GetBytes("username=" + user.Trim + "&password=" + pass.Trim)
- RequestPOST.ContentLength = data.Length
- Dim stream As Stream = RequestPOST.GetRequestStream()
- stream.Write(data, 0, data.Length)
- stream.Close()
- Dim ResponsePOST As HttpWebResponse = DirectCast(RequestPOST.GetResponse(), HttpWebResponse)
- stream = ResponsePOST.GetResponseStream()
- Dim reader As New StreamReader(stream)
- Dim input As String = reader.ReadToEnd()
- result = input
- For Each cook As Cookie In ResponsePOST.Cookies
- cookies.Add(cook)
- If cook.Name = "csrftoken" Then
- csrftoken = cook.Value
- End If
- If cook.Name = "mid" Then
- mid = cook.Value
- End If
- If cook.Name = "sessionid" Then
- sessionid = cook.Value
- End If
- If cook.Name = "ds_user_id" Then
- ds_user_id = cook.Value
- End If
- If cook.Name = "ig_dau_dismiss" Then
- ig_dau_dismiss = cook.Value
- End If
- Next
- If input.Contains("authenticated"": true") Then
- MsgBox("LOGIN TRUE")
- RequestPOST.Abort()
- ResponsePOST.Close()
- Else
- If input.Contains("authenticated"": False") Then
- MsgBox("LOGIN FALSE")
- RequestPOST.Abort()
- ResponsePOST.Close()
- End If
- End If
- Catch ex As WebException
- ProjectData.SetProjectError(ex)
- result = New StreamReader(ex.Response.GetResponseStream()).ReadToEnd()
- ProjectData.ClearProjectError()
- End Try
- Return result
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement