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:
I'll probably make a Github soon.... anyway enjoy.Code: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
Results 1 to 33 of 33
Thread: VB.Net Gaia Login Example.
- 30 Mar. 2013 08:56am #1
VB.Net Gaia Login Example.
There's nothing ideal about being real, there's so many flaws to cover and conceal.
- 30 Mar. 2013 10:35pm #2
- 30 Mar. 2013 10:38pm #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.Last edited by Kitsune; 30 Mar. 2013 at 10:40pm.
There's nothing ideal about being real, there's so many flaws to cover and conceal.
- 30 Mar. 2013 10:40pm #4
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
- 30 Mar. 2013 10:43pm #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.There's nothing ideal about being real, there's so many flaws to cover and conceal.
- 30 Mar. 2013 11:55pm #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.
- 31 Mar. 2013 02:21am #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.There's nothing ideal about being real, there's so many flaws to cover and conceal.
- 31 Mar. 2013 02:34am #8
He's offering constructive refactoring tips. You seem like you're getting defensive. Example or not he's just passing some advice.
- 02 Apr. 2013 09:29pm #9
Login no longer works ill have to mess around with the code and see if i can get a new login working.
There's nothing ideal about being real, there's so many flaws to cover and conceal.
- 02 Apr. 2013 10:09pm #10
Mine still works just fine, so I doubt they changed anything with the login.
- 02 Apr. 2013 11:18pm #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.There's nothing ideal about being real, there's so many flaws to cover and conceal.
- 02 Apr. 2013 11:34pm #12
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.
Code: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')
- 02 Apr. 2013 11:59pm #13
That's what happens when you don't try to reinvent the wheel. Stuff keeps working!
- 03 Apr. 2013 12:11am #14
Moderator Bachelor of Science in Virginity
- Age
- 31
- Join Date
- Nov. 2009
- Location
- Toronto
- Posts
- 5,421
- Reputation
- 546
- LCash (Rank 3)
- 1.96
- 03 Apr. 2013 12:19am #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.
Code: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
- 03 Apr. 2013 12:26am #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.
- 03 Apr. 2013 12:27am #17
Moderator Bachelor of Science in Virginity
- Age
- 31
- Join Date
- Nov. 2009
- Location
- Toronto
- Posts
- 5,421
- Reputation
- 546
- LCash (Rank 3)
- 1.96
- 03 Apr. 2013 12:30am #18
- 03 Apr. 2013 12:32am #19
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).
- 03 Apr. 2013 12:33am #20
- 03 Apr. 2013 12:34am #21
- 03 Apr. 2013 12:37am #22
- 03 Apr. 2013 12:50am #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.There's nothing ideal about being real, there's so many flaws to cover and conceal.
- 03 Apr. 2013 01:02am #24
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)
Code: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
- 03 Apr. 2013 01:12am #25
I think i'd rather juse use regex.
There's nothing ideal about being real, there's so many flaws to cover and conceal.
- 03 Apr. 2013 01:40am #26
- 03 Apr. 2013 02:02am #27
- 03 Apr. 2013 02:58am #28
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.
- 03 Apr. 2013 03:01am #29
- 03 Apr. 2013 03:03am #30
- 03 Apr. 2013 03:05am #31
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.
- 03 Apr. 2013 03:05am #32
- 03 Apr. 2013 03:24am #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.There's nothing ideal about being real, there's so many flaws to cover and conceal.