[VB6] Making Logins

Discussion in 'Code Snippets and Tutorials' started by omgcat, May 5, 2007.

  1. omgcat

    omgcat Level IV

    Joined:
    Jan 31, 2007
    Messages:
    1,137
    Likes Received:
    0
    Ill give you some of the code to make a easy login... You will code the rest!


    Ok. first thing to do is add the http wrapper, and moduels into the program.. or else it wont compile right!

    Make a textbox, label it txtuser, make another one right under it and label it txtpass.

    After you have done this, make a button.. label the button cmdlogin.


    After you have done this, Use this code.. I will break it up into pieces.. so you can understand it. (take out the spaces)


    Code (Visual Basic):
    1. <div class="vb" id="{CB}" style="font-family: monospace;"><ol><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"> </li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> cmdLogin_Click<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></li><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">Dim</span> strHTML <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">strHTML = w.<span style="color: #66cc66;">PostWrapper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"http://neopets .com/login.phtml"</span>, <span style="color: #ff0000;">"username="</span> & txtuser & <span style="color: #ff0000;">"&password="</span> & txtpass & <span style="color: #ff0000;">"&destination=%2Fpetcentral.phtml"</span>, <span style="color: #ff0000;">"http://neopets .com/hi.phtml"</span><span style="color: #66cc66;">)</span></li><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">If</span> <span style="color: #b1b100;">InStr</span><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">1</span>, strHTML, <span style="color: #ff0000;">"badpassword"</span><span style="color: #66cc66;">)</span> <span style="color: #b1b100;">Then</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">msgbox</span> <span style="color: #ff0000;">"Bad Password for account "</span> & txtuser.<span style="color: #66cc66;">Text</span></li><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">ElseIf</span> <span style="color: #b1b100;">InStr</span><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">1</span>, strHTML, <span style="color: #ff0000;">"This account has been"</span><span style="color: #66cc66;">)</span> <span style="color: #b1b100;">Then</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">msgbox</span> <span style="color: #ff0000;">"The account "</span> & txtuser.<span style="color: #66cc66;">Text</span> & <span style="color: #ff0000;">" has been frozen"</span></li><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">ElseIf</span> <span style="color: #b1b100;">InStr</span><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">1</span>, strHTML, <span style="color: #ff0000;">"petcentral"</span><span style="color: #66cc66;">)</span> <span style="color: #b1b100;">Then</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">msgbox</span> <span style="color: #ff0000;">"Logged in as "</span> & txtuser.<span style="color: #66cc66;">Text</span></li></ol></div>
    Ok the first part is this:

    Code (Visual Basic):
    1. <div class="vb" id="{CB}" style="font-family: monospace;"><ol><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">Dim</span> strHTML <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">strHTML = w.<span style="color: #66cc66;">PostWrapper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"http://neopets .com/login.phtml"</span>, <span style="color: #ff0000;">"username="</span> & txtuser & <span style="color: #ff0000;">"&password="</span> & txtpass & <span style="color: #ff0000;">"&destination=%2Fpetcentral.phtml"</span>, <span style="color: #ff0000;">"http://neopets .com/hi.phtml"</span><span style="color: #66cc66;">)</span></li></ol></div>
    This part of the code is telling the wrappper (httpwrapper) to go to the neopets website and put in the parts of text it needs to log in. This is what it does.. in example if the txtuser is omgcat and the txtpass is omgcat

    http://neopets .com/login.phtml/username=omgcat&password=omgcat&destination=%2Fpetcentral.phtml

    Code (Visual Basic):
    1. <div class="vb" id="{CB}" style="font-family: monospace;"><ol><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">If</span> <span style="color: #b1b100;">InStr</span><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">1</span>, strHTML, <span style="color: #ff0000;">"badpassword"</span><span style="color: #66cc66;">)</span> <span style="color: #b1b100;">Then</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">msgbox</span> <span style="color: #ff0000;">"Bad Password for account "</span> & txtuser.<span style="color: #66cc66;">Text</span></li><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">ElseIf</span> <span style="color: #b1b100;">InStr</span><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">1</span>, strHTML, <span style="color: #ff0000;">"This account has been"</span><span style="color: #66cc66;">)</span> <span style="color: #b1b100;">Then</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">msgbox</span> <span style="color: #ff0000;">"The account "</span> & txtuser.<span style="color: #66cc66;">Text</span> & <span style="color: #ff0000;">" has been frozen"</span></li><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">ElseIf</span> <span style="color: #b1b100;">InStr</span><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">1</span>, strHTML, <span style="color: #ff0000;">"petcentral"</span><span style="color: #66cc66;">)</span> <span style="color: #b1b100;">Then</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">msgbox</span> <span style="color: #ff0000;">"Logged in as "</span> & txtuser.<span style="color: #66cc66;">Text</span></li></ol></div>
    This is telling the program to search the page and look for the words. and if it finds the specific word it will tell you if it has logged in or not.

    You have successfully made a login.

    TAKE OUT ALL OF THE SPACES INBETWEEN LINKS!!
     
  2. FastBullet

    FastBullet Level IV

    Joined:
    Feb 7, 2007
    Messages:
    2,137
    Likes Received:
    45
    Maybe you should explain a little more because i keep getting errors :p
     
  3. tac123

    tac123 Level I

    Joined:
    Apr 29, 2007
    Messages:
    124
    Likes Received:
    0
    It should also be noted that this is a detectable login method because it does not login in the two stages that a normal user would have to take. First entering their username, and then entering a password. Along with a few other reasons whose determination I'll leave as an exercise to the reader.
     
  4. gawjus1234

    gawjus1234 Level III

    Joined:
    May 22, 2007
    Messages:
    518
    Likes Received:
    3
    Location:
    Las Vegas
    wow that helped a lot. i have been having trouble with my httpwrapper. what one do you use? thanks in advance. oh yeah. +rep (a million times if i could.)
     
  5. the_skip

    the_skip Level IV

    Joined:
    Dec 25, 2006
    Messages:
    2,354
    Likes Received:
    1
    Location:
    Indiana
    the one posted in code snippets
     
  6. omgcat

    omgcat Level IV

    Joined:
    Jan 31, 2007
    Messages:
    1,137
    Likes Received:
    0
    Here is my new guide, it is more.. easier to understand XD

    ----


    ^^ So you just want to start making neopets programs? You first need to know how to make a Login.

    The first thing you need to do is locate your Http Wrapper and your Sleep and stuff moduel.

    You need to make 2 textboxes.. make the name of one of them txtuser and the other one txtpass. (make two labels next to these, one username for txtuser and the other password next to txtpass)




    Make a Command button and name it CmdLogin and make its caption Login..



    Now double click the form, and delete all code in there.



    And then paste this code into it.

    Code (Text):
    1.  Private Sub cmdLogin_Click()
    2. Dim strHTML As String
    3. strHTML = w.PostWrapper("http://neopets .com/login.phtml", "username=" & txtuser & "&password=" & txtpass & "&destination=%2Fpetcentral.phtml", "http://neopets .com/hi.phtml")
    4. If InStr(1, strHTML, "badpassword") Then
    5. msgbox "Bad Password for account " & txtuser.Text
    6. ElseIf InStr(1, strHTML, "This account has been") Then
    7. msgbox "The account " & txtuser.Text & " has been frozen"
    8. ElseIf InStr(1, strHTML, "petcentral") Then
    9. msgbox "Logged in as " & txtuser.Text
    10. End If
    11. End Sub
    Now to check if it worked, go up to the top and press the play button. Type in username and password for a working account, frozen account, then a wrong password for an account.. Good luck!

    Take out spaces.. :D
     
  7. gawjus1234

    gawjus1234 Level III

    Joined:
    May 22, 2007
    Messages:
    518
    Likes Received:
    3
    Location:
    Las Vegas
    every single time i hit the command button i get an object required error. whats going on?
     
  8. omgcat

    omgcat Level IV

    Joined:
    Jan 31, 2007
    Messages:
    1,137
    Likes Received:
    0
    Are you putting http wrapper on the form and naming it w?
     
  9. sebzanga

    sebzanga Level III

    Joined:
    May 27, 2007
    Messages:
    625
    Likes Received:
    3
    Very good code O.O
     
  10. gawjus1234

    gawjus1234 Level III

    Joined:
    May 22, 2007
    Messages:
    518
    Likes Received:
    3
    Location:
    Las Vegas
    i cant put the wrapper in the form can i? and i can't change the name of the wrapper only the sleep and stuff module. sorry for being such a noob
     
  11. Poprockz

    Poprockz Level II

    Joined:
    Jul 10, 2007
    Messages:
    202
    Likes Received:
    1
    Location:
    Unknown
    I'm new to vb6 programming but I've had some experience with logins .. and yes, you do put it on the form. Click the wrapper on your sidebar and put it somewhere on your form.