Advertisement
Guest User

Untitled

a guest
Feb 4th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. Private cookies As New CookieContainer
  2. Dim csrftoken As String = ""
  3. Dim mid As String = ""
  4. Dim sessionid As String = ""
  5. Dim ig_dau_dismiss As String = ""
  6. Dim ds_user_id As String = ""
  7. Dim cooks As String = ""
  8. Private Function login(ByVal user As String, ByVal pass As String) As String
  9. Dim result As String
  10. Try
  11. Dim RequestGET As HttpWebRequest = DirectCast(WebRequest.Create("https://www.instagram.com"), HttpWebRequest)
  12. RequestGET.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:58.0) Gecko/20100101 Firefox/58.0"
  13. RequestGET.Method = "GET"
  14. RequestGET.CookieContainer = New CookieContainer
  15. RequestGET.KeepAlive = True
  16. Dim ResponseGET As HttpWebResponse = DirectCast(RequestGET.GetResponse(), HttpWebResponse)
  17. For Each cook As Cookie In ResponseGET.Cookies
  18. If cook.Name = "csrftoken" Then
  19. csrftoken = cook.Value
  20. End If
  21. If cook.Name = "mid" Then
  22. mid = cook.Value
  23. End If
  24. Next
  25. cooks += "mid=" + mid + ";csrftoken=" + csrftoken
  26. RequestGET.Abort()
  27. ResponseGET.Close()
  28. Dim RequestPOST As HttpWebRequest = DirectCast(WebRequest.Create("https://www.instagram.com/accounts/login/ajax/"), HttpWebRequest)
  29. RequestPOST.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:58.0) Gecko/20100101 Firefox/58.0"
  30. RequestPOST.Method = "POST"
  31. RequestPOST.Timeout = 5000
  32. RequestPOST.Referer = "https://www.instagram.com/"
  33. RequestPOST.Headers.Add("X-CSRFToken", csrftoken)
  34. RequestPOST.Headers.Add("Cookie", cooks)
  35. RequestPOST.ContentType = "application/x-www-form-urlencoded"
  36. Dim data As Byte() = Encoding.UTF8.GetBytes("username=" + user.Trim + "&password=" + pass.Trim)
  37. RequestPOST.ContentLength = data.Length
  38. Dim stream As Stream = RequestPOST.GetRequestStream()
  39. stream.Write(data, 0, data.Length)
  40. stream.Close()
  41. Dim ResponsePOST As HttpWebResponse = DirectCast(RequestPOST.GetResponse(), HttpWebResponse)
  42. stream = ResponsePOST.GetResponseStream()
  43. Dim reader As New StreamReader(stream)
  44. Dim input As String = reader.ReadToEnd()
  45. result = input
  46. For Each cook As Cookie In ResponsePOST.Cookies
  47. cookies.Add(cook)
  48. If cook.Name = "csrftoken" Then
  49. csrftoken = cook.Value
  50. End If
  51. If cook.Name = "mid" Then
  52. mid = cook.Value
  53. End If
  54. If cook.Name = "sessionid" Then
  55. sessionid = cook.Value
  56. End If
  57. If cook.Name = "ds_user_id" Then
  58. ds_user_id = cook.Value
  59. End If
  60. If cook.Name = "ig_dau_dismiss" Then
  61. ig_dau_dismiss = cook.Value
  62. End If
  63. Next
  64. If input.Contains("authenticated"": true") Then
  65. MsgBox("LOGIN TRUE")
  66. RequestPOST.Abort()
  67. ResponsePOST.Close()
  68. Else
  69. If input.Contains("authenticated"": False") Then
  70. MsgBox("LOGIN FALSE")
  71. RequestPOST.Abort()
  72. ResponsePOST.Close()
  73. End If
  74. End If
  75. Catch ex As WebException
  76. ProjectData.SetProjectError(ex)
  77. result = New StreamReader(ex.Response.GetResponseStream()).ReadToEnd()
  78. ProjectData.ClearProjectError()
  79. End Try
  80. Return result
  81. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement