Results 1 to 4 of 4

Thread: [C#] Basic Neopets Login

  1. #1
    Little Brother


    Zachafer's Avatar
    Join Date
    Dec 2011
    Gender
    Posts
    1,206
    Thanks
    723
    Thanked 1,392 Times in 651 Posts


    Downloads
    81
    Uploads
    17
    Mentioned
    497 Post(s)
    Time Online
    21 d 17 h 32 m
    Avg. Time Online
    16 m
    Rep Power
    14

    [C#] Basic Neopets Login

    Hello. Today I will be showing you the start of nearly all Neo programs: the login!

    Let's get started. I'm assuming you have the tools necessary for all of this:
    [list][*]Web browser ([URL="http://clraik.com/forum/showthread.php?14132-C-NeoAccount-Class-(includes-HTTP-requests)[/url]

    Once you have NeoAccount.cs added to your Project, open up your browser and navigate to Neopets.com

    I'm using Firefox with LiveHTTPHeaders in this tutorial. It is possible to use a different browser with Fiddler but I prefer Firefox.

    Make sure the Capture checkbox is clicked in LiveHTTPHeaders and login to Neopets. You'll see the headers filling up fast. The first one is what we want (to login.phtml)


    Notice those 4 things I pointed out.

    The top line is the URL we are sending the request to.
    The second line tells you what type of request we are sending. (Most commonly GET or POST)
    The referer tells the website what page we are coming from. This can be spoofed easily.
    The data is the data we are POST-ing to the page. Content-Length and the data are sent in POST requests, not GET.

    Now we can use our NeoAccount.cs class to login to Neo.


    But wait there is a very much easier way built into the NeoAccount class! To log in to Neo using the class's .Login() method:
    This concludes my tutorial. I have attached the sample project files. If you have any questions, comments, or suggestions, feel free to post them below.
    Attached Files Attached Files

  2. The Following 2 Users Say Thank You to Zachafer For This Useful Post:

    Infamous Joe (12-01-2013),MikeyR (12-01-2013)

  3. #2

    MikeyR's Avatar
    Join Date
    Jan 2013
    Gender
    Location
    Toronto
    Age
    25
    Posts
    102
    Thanks
    9
    Thanked 44 Times in 34 Posts


    Downloads
    58
    Uploads
    0
    Mentioned
    9 Post(s)
    Time Online
    8 d 9 h 37 m
    Avg. Time Online
    6 m
    Rep Power
    5
    After the login passes true, everything in the curly braces would be whatever you want the program to do correct?

    Definitely digging the tutorial. Also enjoying that they seem to be coming out right as I decided I want to practice C# with neo programs.

    EDIT: Looking through the Login() code, I have questions about understanding:



    1. cookieMatch - string of the cookie data found after the POST request?
    2. I think I understand after some reading, but Groups[1] = neologin=[a-z0-9_]{3,20}%2B[a-z0-9]{40}

    And then if there were more brackets in the regex:
    (neologin=[a-z0-9_]{3,20}%2B[a-z0-9]{40}) (This would be Groups[2]) (and Groups[3] right?)
    3. And then cookieMatch.Success just returns bool if the cookie string was found?

    With incorrect login credentials it doesn't set a cookie, then the method returns false because there was no cookie set to find, correct?
    Last edited by MikeyR; 12-01-2013 at 09:29 PM.

  4. #3
    Little Brother


    Zachafer's Avatar
    Join Date
    Dec 2011
    Gender
    Posts
    1,206
    Thanks
    723
    Thanked 1,392 Times in 651 Posts


    Downloads
    81
    Uploads
    17
    Mentioned
    497 Post(s)
    Time Online
    21 d 17 h 32 m
    Avg. Time Online
    16 m
    Rep Power
    14
    After the login passes true, everything in the curly braces would be whatever you want the program to do correct?
    Yes





    With incorrect login credentials, the regex won't match the html. Thus, cookieMatch.Groups[1].Value will equal "" and cookieMatch.Success will be false.

  5. #4

    MikeyR's Avatar
    Join Date
    Jan 2013
    Gender
    Location
    Toronto
    Age
    25
    Posts
    102
    Thanks
    9
    Thanked 44 Times in 34 Posts


    Downloads
    58
    Uploads
    0
    Mentioned
    9 Post(s)
    Time Online
    8 d 9 h 37 m
    Avg. Time Online
    6 m
    Rep Power
    5
    Quote Originally Posted by Zachafer View Post
    With incorrect login credentials, the regex won't match the html. Thus, cookieMatch.Groups[1].Value will equal "" and cookieMatch.Success will be false.
    Yea I know a bit of regex from school this semester dealing with shell scripts. I pretty much followed it all so that's sick. Stoked that this random UNIX class that I had to take is totally worth while. Although shell scripts and regex are pretty good to know, not sure how much I'll use them in game programming.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •