A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

VB.Net Gaia Login Example.

3.5k views · started by Kitsune ·
#1
VB.Net Gaia Login Example.
Credits to Stapled for original login in C#, after some time i was able to convert it to .Net.
Credits to Chad from his String Extensions in C#, converted to .Net

What you'll need:
VB.NET
My Wrapper With Addons
The Ability to Copy Pasta

Example:

Dim wrapper As New Wrapper
Dim html, user, pass As String

Sub Main()
Console.Write("Username: ")
user = Console.ReadLine()
Console.Write("Password: ")
pass = Console.ReadLine()
GaiaLogin(user, pass)
End Sub

Public Function GaiaLogin(username As String, password As String) As [boolean]
Dim pd As String
wrapper.WebRequest(html, "http://www.gaiaonline.com/", "GET", "", "")
pd = wrapper.Between(html, "</fieldset>", "</form>").Replace("data-value", "")
Dim n As List(Of String) = wrapper.gasb(pd, "name=""", """")
Dim v As List(Of String) = wrapper.gasb(pd, "value=""", """")
Dim postdata As String = ((((((n(0) + "=" + v(0) & "&") + n(1) & "=") + v(1) & "&") + n(2) & "=") + v(2) & "&") + n(3) & "=") + v(3) & "&" & "username=" & username & "&password=" & password
Dim login As String
wrapper.WebRequest(login, "http://www.gaiaonline.com/auth/login/", "POST", postdata, "")
wrapper.WebRequest(login, "http://www.gaiaonline.com/", "GET", "", "")

If login.Contains("Welcome back") Then
Console.WriteLine("Pass")
Console.ReadLine()
Else
Console.WriteLine("Fail")
Console.ReadLine()
End If

Return login.Contains("Welcome back")

End Function[/boolean]


I'll probably make a Github soon.... anyway enjoy.
#2
Kitsune wrote:
Credits to Stapled for original login in C#, after some time i was able to convert it to .Net.
Credits to Chad from his String Extensions in C#, converted to .Net

What you'll need:
VB.NET
My Wrapper With Addons
The Ability to Copy Pasta

Example:
Dim wrapper As New Wrapper
Dim html, user, pass As String

Sub Main()
Console.Write("Username: ")
user = Console.ReadLine()
Console.Write("Password: ")
pass = Console.ReadLine()
GaiaLogin(user, pass)
End Sub

Public Function GaiaLogin(username As String, password As String) As [boolean]
Dim pd As String
wrapper.WebRequest(html, "http://www.gaiaonline.com/", "GET", "", "")
pd = wrapper.Between(html, "</fieldset>", "</form>").Replace("data-value", "")
Dim n As List(Of String) = wrapper.gasb(pd, "name=""", """")
Dim v As List(Of String) = wrapper.gasb(pd, "value=""", """")
Dim postdata As String = ((((((n(0) + "=" + v(0) & "&") + n(1) & "=") + v(1) & "&") + n(2) & "=") + v(2) & "&") + n(3) & "=") + v(3) & "&" & "username=" & username & "&password=" & password
Dim login As String
wrapper.WebRequest(login, "http://www.gaiaonline.com/auth/login/", "POST", postdata, "")
wrapper.WebRequest(login, "http://www.gaiaonline.com/", "GET", "", "")

If login.Contains("Welcome back") Then
Console.WriteLine("Pass")
Console.ReadLine()
Else
Console.WriteLine("Fail")
Console.ReadLine()
End If

Return login.Contains("Welcome back")

End Function[/boolean]


I'll probably make a Github soon.... anyway enjoy.


I haven't really messed with VB or the HTTP login parts of Gaia, but couldn't you technically just load method 109 from the GSI, and check it's status return to see if a login worked as opposed to seeing if a string exists in the page?
#3
Yes you can, either way works.

I really don't need method 109 unless i plan on making a flash-less slot client (or something else that can be ran through GSI), then i'd have to get the session from 109 before proceeding with the bot.
#4
Kitsune wrote:
Yes you can, either way works.


Would probably be faster just to do that as opposed to checking if a string exists in the return page. It may just be me but I don't really think you should be using a string that could change over time to check if a login worked, as opposed to something that will give you a True or False return such as the JSON 109 method
#5
The thing with that though "Welcome back" has been in html for ages, if that changes i could just use something else that will always be in the page no matter what if the login was correct.

Also as for speed, 109 probably is faster, but i only use it if im gonna make a bot through GSI, that way i can easily get my Session ID.
#6
You should still make it's successful login check a bit more precise in my opinion. I always try to make my code never do success checks or returns by the presences of a string where possible due to the uncertainty of it. Loading the GSI method takes off about 1 milisecond (may not sound much but it adds up), and gives you the certainty and stability of your check.
#7
Well im using the GSI to check on my current project right now, also this was an EXAMPLE.
The actual code im using ATM differs and i coded a gaia login to my wrapper class that checks valid login via GSI.
#8
He's offering constructive refactoring tips. You seem like you're getting defensive. Example or not he's just passing some advice.
#9
Login no longer works ill have to mess around with the code and see if i can get a new login working.
#10
Mine still works just fine, so I doubt they changed anything with the login.
#11
I scanned requests that says otherwise, this login if you cant tell grabs the strings off the home page and logs in from there.

Stapled's login should also been broken as well.
#12
Kitsune wrote:
I scanned requests that says otherwise, this login if you cant tell grabs the strings off the home page and logs in from there.

Stapled's login should also been broken as well.


I wouldn't know, mine will work no matter how many inputs they add to it. Never seen Stapled's either but if you want to avoid this in the future don't hardcode the post data, have it automatically parse the form.

Here's one I threw together quickly that won't break unless they drastically do a site redesign. If it's not clear, it converts all inputs in the login form into a dictionary and updates the few parts that need to be before posting. Could have done it all through lxml, but the form_post with lxml was being weird with what I wanted it to do.
import requests
from hashlib import md5
from lxml.html import parse, submit_form, tostring

def html_auth(username, pwd):
session = requests.Session()
uri = 'http://www.gaiaonline.com/auth/login/'
auth_form = dict(parse(uri).getroot().forms[0].fields)
auth_form['username'] = username
auth_form['password'] = ''
auth_form['redirect'] = '/chat/gsi/?v=json&m=[[109]]'
chap = md5(md5(pwd).hexdigest() + auth_form['token']).hexdigest()
auth_form['chap'] = chap
auth_form['signInButton'] = 'Log in'
try:
session.post(uri, params=auth_form).json()[0][2]
return session
except:
raise Exception('error logging in')
[/2][/0][/109][/0]
#13
That's what happens when you don't try to reinvent the wheel. Stuff keeps working!
#14
The easiest way to fix it is to remove "<a name" and "value="value"".
#15
Nah, it's still better to parse all of the form fields simultaneously rather than grab each individually. The following still works, same as Trees except it just uses regular expressions to parse the form fields.

    def login(self, username, password):
source = self.request("http://www.gaiaonline.com/")
inputPattern = re.compile("<input([^>]+)>")
inputs = inputPattern.findall(source)

fieldPattern = re.compile("([a-zA-Z0-9\-\_]+)\=\"([^\"]{0,})\"")
fieldList = {}

for y in range(0, len(inputs)):
fields = fieldPattern.findall(inputs[y])
name = ""
val = ""
for z in range(0, len(fields)):
if fields[z][0] == "name":
name = fields[z][1]
elif fields[z][0] == "value":
val = fields[z][1]

try:
fieldList[name] = val
except:
pass

fieldList["username"] = username
fieldList["password"] = password

login = self.request("http://www.gaiaonline.com/auth/login/", fieldList)

return login.find("Welcome back") != -1[/name][/1][/z][/0][/z][/1][/z][/0][/z][/y]


edit: when that was originally written a while ago, there was only one form on the homepage. If you were being extra cautious, you'd want to ensure you're only grabbing inputs from the login form, and then to verify whether it logged in you'd be better off checking the existence of a valid session cookie.
#16
Yup, grabbing everything individually only causes pain later on. When making something (especially HTML related) it needs to be somewhat fool-proof to the HTML changing. They basically give you everything you need right between two form tags, so hard coding the post data params or length is actually fairly redundant, especially when you are working in a language that provides you with the tools to get all you need.
#17
Regex has never made sense to me. It's too hard :(.
#18
Stapled wrote:
Regex has never made sense to me. It's too hard :(.


A lot of the time you don't even need to use regex these days, as there are a lot of modules or tools that will basically do it for you. I can really only think of a few times I've had to recently use regex.
#19
Stapled wrote:
Regex has never made sense to me. It's too hard :(.


It's essentially just the ability to search strings of text for patterns. In this example, if you think of the login form, each form attribute adheres to a common pattern (and that's obviously by design). I'd highly suggest you read up and learn how to take advantage of it, as its fairly universal and used in most languages (you'll definitely come across it more than a few times in your compsci degree).
#20
Tree wrote:
A lot of the time you don't even need to use regex these days, as there are a lot of modules or tools that will basically do it for you. I can really only think of a few times I've had to recently use regex.


Regex is used a lot. I'll admit I haven't had too much need in Python, but PHP/Java/JSP/XML I've had to use it a fair bit.
#21
Artificial wrote:
It's essentially just the ability to search strings of text for patterns. In this example, if you think of the login form, each form attribute adheres to a common pattern (and that's obviously by design). I'd highly suggest you read up and learn how to take advantage of it, as its fairly universal and used in most languages (you'll definitely come across it more than a few times in your compsci degree).


Plus it's not that hard once you actually figure it out.
#22
Artificial wrote:
Regex is used a lot. I'll admit I haven't had too much need in Python, but PHP/Java/JSP/XML I've had to use it a fair bit.


I was probably meaning mostly towards Python, because that's mostly what I've been using these days, including replacing PHP. I've never done much in Java so I can't say much on that. It's a good thing to learn nonetheless.
#23
I'll look at it this weekend when i'll actually have time.
I might code a regex function into my wrapper and parse the fields within the form.
#24
Kitsune wrote:
I'll look at it this weekend when i'll actually have time.
I might code a regex function into my wrapper and parse the fields within the form.


I did a quick google search, and it honestly doesn't even seem like you will need to regex for this as there are built in Imports for VB that can handle that kind of functionality with HTML, but I still recommend learning regex in some way or another.

Edit: Example I found on stackoverflow (Doesn't get forms, just an example)

Imports mshtml

Function parseMyHtml(ByVal htmlToParse$) As String
Dim htmlDocument As IHTMLDocument2 = New HTMLDocumentClass()
htmlDocument.write(htmlToParse)
htmlDocument.close()

Dim allElements As IHTMLElementCollection = htmlDocument.body.all

Dim allInputs As IHTMLElementCollection = allElements.tags("a")
Dim element As IHTMLElement
For Each element In allInputs
element.title = element.innerText
Next

Return htmlDocument.body.innerHTML
End Function
#25
I think i'd rather juse use regex.
#26
Kitsune wrote:
I think i'd rather juse use regex.


Any specific reason?
#27
Tree wrote:
Any specific reason?


No, lol.
#28
No, lol.


In most cases, if a language gives me a shortcut or method to do something better than I could do it myself, I'm normally going to use it. You can learn how to do it on your own on the side to learn how its done and works, but it's kind of redundant to actually avoid using built in methods unless you absolutely have to.
#29
Tree wrote:
In most cases, if a language gives me a shortcut or method to do something better than I could do it myself, I'm normally going to use it. You can learn how to do it on your own on the side to learn how its done and works, but it's kind of redundant to actually avoid using built in methods unless you absolutely have to.


My reason is I personally like regex for parsing more than other functions >.>
That's why
Also Unintelligible fuck off.
#30
Kitsune wrote:

Also Unintelligible fuck off.


u dont kno me son
u cant c me
u cant c me
#31
Kitsune wrote:
My reason is I personally like regex for parsing more than other functions >.>
That's why
Also Unintelligible fuck off.


Wouldn't need to ab an entire different function. I haven't done VB in about 10 years, but just looking at the code it could easily be a line or two in whatever function you are using. Plus, if you google it up, there are actually recommendations on not using regex on HTML. You can use whatever you want though.
#32
u dont kno me son
u cant c me
u cant c me


U CANT C HIM
U DONT NO HIM
#33
inb4 lips enlarge...

Anyway, im not going to use it parse the whole HTML from the page, it should do fine for me and if i have problems i might use the method you posted or find my own.
Thank you for trying to show me other methods but for now ill pass thank you.