Mybb,phpbb login in application!

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
5 posts Page 1 of 1
Contributors
User avatar
pip
VIP - Donator
VIP - Donator
Posts: 156
Joined: Tue Jul 12, 2011 3:13 am

Mybb,phpbb login in application!
pip
Ok so this is gonna be me using http request to make login i still have not figured out register but it can be done this uses classes and i am doing mybb version so if you want to try this youll need mybb from mybb.com and a hosting site like 000webhost.com and to upload files to ftp and install the forums this can be done with lots of forum versions but is kind of hard cause each one has different coding i am using mybb cause is only one i figured out so far!

What is needed in the project:
1 button
2 textbox's and labels!
3 classes:
class 1: HTTPWorker.vb
class 2: Forum.vb
class 3: MyBB.vb

Now for the coding:

Button 1:
replace yourmybbforums with your site!
Code: Select all
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim wrkr As New HTTPWorker()
        Dim myBBForum As New MyBB("http://yourmybbforums", TextBox1.Text, TextBox2.Text)
        If wrkr.login(myBBForum) Then
            MsgBox("Logged in successfully!")
            Me.Hide()
            Main.Show()
        Else
            MsgBox("Invalid account, please try again! Register if you don't have an account.")
        End If
    End Sub
HTTPWorker Class:
Code: Select all
Imports System.Net
Imports System.Text
Imports System.IO.Compression
Public Class HTTPWorker
    Public Shared cookies As CookieContainer
    Private data As Byte()

    Public Function login(ByVal forumInstance As Forum) As Boolean
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse
        Dim stream As IO.Stream

        cookies = New CookieContainer
        Try
            request = WebRequest.Create(forumInstance.loginUrl)
            setConnectionParameters(request)

            data = Encoding.ASCII.GetBytes(forumInstance.logindata)
            request.ContentLength = data.Length
            stream = request.GetRequestStream()
            stream.Write(data, 0, data.Length)
            stream.Flush()
            stream.Close()

            response = request.GetResponse()

            If forumInstance.isLoggedIn(cookies) Then
                Return True
            End If
        Catch ex As Exception
            'do something with the exception
        End Try
        Return False
    End Function

    Public Sub setConnectionParameters(ByRef request As HttpWebRequest)
        With request
            .Method = "POST"
            .Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
            .ContentType = "application/x-www-form-urlencoded"
            .Proxy = Nothing
            .CookieContainer = cookies
            .KeepAlive = True
            .ServicePoint.Expect100Continue = False
            .UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8) Gecko/20051111 Firefox/1.5; FBI-version/0.07"
            '.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate") if you want to speed up the steam reading (most boards support this)
        End With
    End Sub

    'this function not implemented, it is added to show how to link the cookies from the login
    Public Sub navTo()
        'Dim request As HttpWebRequest
        'request.CookieContainer = cookies
        'etcetc: you could set idletime, speed if you simultaniously want to fire requests, headers, method (get/post), etc
    End Sub

    'Note: to read the result in login()
    '--If you want to read the result (using compression techniques to speed it up--
    'Dim responseStream As IO.Stream = response.GetResponseStream()

    'If (response.ContentEncoding.ToLower().Contains("gzip")) Then
    '    responseStream = New GZipStream(responseStream, CompressionMode.Decompress)
    'ElseIf (response.ContentEncoding.ToLower().Contains("deflate")) Then
    '    responseStream = New DeflateStream(responseStream, CompressionMode.Decompress)
    'End If

    'Dim streamReader As IO.StreamReader = New IO.StreamReader(responseStream, Encoding.Default)
    'Dim result As String = streamReader.ReadToEnd().Trim()
    'streamReader.Close()
    '--
End Class
Forum Class
Code: Select all
Public MustInherit Class Forum
    Private _logindata As String
    Private _loginUrl As String
    Private _url As String
    Private _username As String
    Private _defaultCookieName As String
    Private _defaultCookieSearch As String

    Public Sub New(ByVal url As String, ByVal loginUrl As String, ByVal username As String, ByVal cookieName As String, _
  ByVal cookieSearch As String, Optional ByVal data As String = "")
        Me._url = url
        Me.loginUrl = loginUrl
        Me.logindata = data
        Me.username = username
        Me._defaultCookieName = cookieName
        Me._defaultCookieSearch = cookieSearch
    End Sub

    Public MustOverride Function isLoggedIn(ByVal cookies As System.Net.CookieContainer) As Boolean

    Public Property logindata() As String
        Get
            Return Me._logindata
        End Get
        Set(ByVal value As String)
            Me._logindata = value
        End Set
    End Property

    Public Property url() As String
        Get
            Return Me._url
        End Get
        Set(ByVal value As String)
            Me._url = value
        End Set
    End Property
    Public Property loginUrl() As String
        Get
            Return Me._loginUrl
        End Get
        Set(ByVal value As String)
            Me._loginUrl = value
        End Set
    End Property

    Public Property username() As String
        Get
            Return Me._username
        End Get
        Set(ByVal value As String)
            Me._username = value
        End Set
    End Property
    Public Property defaultCookieName() As String
        Get
            Return Me._defaultCookieName
        End Get
        Set(ByVal value As String)
            Me._defaultCookieName = value
        End Set
    End Property
    Public Property defaultCookieSearch() As String
        Get
            Return Me._defaultCookieSearch
        End Get
        Set(ByVal value As String)
            Me._defaultCookieSearch = value
        End Set
    End Property
End Class
MyBB class:
Code: Select all
Imports System.Net
Public Class MyBB
    Inherits Forum

    Public Sub New(ByVal url As String, ByVal username As String, ByVal password As String)
        MyBase.New(url, url & "/member.php?action=login", username, "mybbuser", "", "username=" + username & "&password=" + password & "&submit=Login&action=do_login&url=")
    End Sub

    Public Overrides Function isLoggedIn(ByVal cookies As System.Net.CookieContainer) As Boolean
        If Not IsNothing(cookies.GetCookies(New Uri(url)).Item(defaultCookieName)) Then
            Return True
        End If
        Return False
    End Function
End Class
Found The new methods for other forums posted below:

Phpbb2 class:
Code: Select all
Imports System.Net

Public Class phpBB2
    Inherits Forum

    Public Sub New(ByVal url As String, ByVal username As String, ByVal password As String)
  MyBase.New(url, url & "/login.php", username, "phpBB_WBB_data", "userid%22%3Bi%3A-1%3B%7D", "&username=" + _
  username + "&password=" + password + "&autologin=on&login=Log+in")
    End Sub

    Public Overrides Function isLoggedIn(ByVal cookies As System.Net.CookieContainer) As Boolean
  If Not cookies.GetCookies(New Uri(url)).Item(defaultCookieName).Value.Contains(defaultCookieSearch) Then
    Return True
  End If
  Return False
    End Function
End Class
phpbb3:
Code: Select all
Imports System.Net

Public Class phpBB3
    Inherits Forum

    Public Sub New(ByVal url As String, ByVal username As String, ByVal password As String)
  MyBase.New(url, url & "/ucp.php?mode=login", username, "phpbb3_1fh61_u", "1", _
  "username=" + username + "&password=" + password + "&redirect=&sid=&redirect=&login=Login")
    End Sub

    Public Overrides Function isLoggedIn(ByVal cookies As System.Net.CookieContainer) As Boolean
  If Not cookies.GetCookies(New Uri(url)).Item(defaultCookieName).Value.Equals(defaultCookieSearch) Then
    Return True
  End If
  Return False
    End Function
vbulletin:
Code: Select all
Public Class vBulletin
    Inherits Forum
    Public Sub New(ByVal url As String, ByVal username As String, _
  ByVal password As String)
  MyBase.New(url, url & "/login.php?do=login", username, "vbseo_loggedin", "yes")
  MyBase.logindata = "vb_login_username=" + username + "&vb_login_password=" + password + _
    "&cookieuser=1&s=&securitytoken=guest&do=login&vb_login_md5password=" + Md5String(password) + _
    "&vb_login_md5password_utf=" + Md5String(password)
    End Sub

    Public Overrides Function isLoggedIn(ByVal cookies As System.Net.CookieContainer) As Boolean
  If Not IsNothing(cookies.GetCookies(New Uri(url)).Item(defaultCookieName)) Then
    If cookies.GetCookies(New Uri(url)).Item(defaultCookieName).Value.Contains(defaultCookieSearch) Then
    Return True
    End If
  End If
  Return False
    End Function

    Private Function Md5String(ByVal v As String) As String
  Dim myProv As New System.Security.Cryptography.MD5CryptoServiceProvider
  Dim b As Byte() = System.Text.Encoding.ASCII.GetBytes(v)
  b = myProv.ComputeHash(b)
  Dim str As String = ""
  Dim i As Integer
  For i = 0 To b.Length - 1
    str = (str & b(i).ToString("x2").ToLower)
  Next i
  Return str
    End Function

End Class
ipb2:
Code: Select all
Public Class IPBoard2
    Inherits Forum

    Public Sub New(ByVal url As String, ByVal username As String, ByVal password As String)
  MyBase.New(url, url & "/index.php?act=Login&CODE=01", username, "ipb_username", "", _
  "&referer=" + url + "&UserName=" + username + "&PassWord=" + password + "&CookieDate=1")
    End Sub

    Public Overrides Function isLoggedIn(ByVal cookies As System.Net.CookieContainer) As Boolean

  If Not IsNothing(cookies.GetCookies(New Uri(url)).Item(defaultCookieName)) Then
    Return True
  End If
  Return False
    End Function
End Class
------------------------------------------------------------------------------------------
xtra notez!!

Forum login example and add objects:
Code: Select all
Dim wrkr As New HTTPWorker()
'Dim phpBB2Forum As New phpBB2("http://www.myurl.com", "username", "pass")
wrkr.login(wbb)
Dim vBulletinForum As New vBulletin("http://www.myurl.com", "username", "pass")
wrkr.login(cf)
Dim myBBForum As New myBB("http://www.myurl.com", "username", "pass")
wrkr.login(bb)
Dim phpBB3Forum As New phpBB3("http://www.myurl.com", "username", "pass")
wrkr.login(phpBB3Forum)
You do not have the required permissions to view the files attached to this post.
Last edited by pip on Sat Apr 28, 2012 9:01 pm, edited 2 times in total.
<a href="http://www.points2shop.com/s/xbox_point ... 5082"><img src="http://points2shop.com/images/promotion ... ricoxg.gif" border="0"/></a>
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

cooll;

great tut pip :D
keep up the good working.
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
Coolblade
VIP - Site Partner
VIP - Site Partner
Posts: 126
Joined: Mon Oct 24, 2011 7:04 pm

Love it thanks for sharing
http://www.codingpalace.tk/
User avatar
patrickcosta
New Member
New Member
Posts: 16
Joined: Wed Jun 27, 2012 8:59 pm

Thanks for sharing, but isn't working for me. I tried with admin account and simple user,in both the msgbox appeared :cry:

Here are the codes, see please what's wrong:

Form1
Code: Select all
Public Class Form1
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim wrkr As New HTTPWorker()
        Dim phpBB3Forum As New phpBB3("http://metrotv.forumaster.net/", TextBox1.Text, TextBox2.Text)
        If wrkr.login(phpBB3Forum) Then
            MsgBox("Logged in successfully!")
            Me.Hide()
            main.Show()
        Else
            MsgBox("Invalid account, please try again! Register if you don't have an account.")
        End If
    End Sub
End Class
HTTPWorker
Code: Select all
Imports System.Net
Imports System.Text
Imports System.IO.Compression

Public Class HTTPWorker
    Public Shared cookies As CookieContainer
    Private data As Byte()

    Public Function login(ByVal forumInstance As Forum) As Boolean
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse
        Dim stream As IO.Stream

        cookies = New CookieContainer
        Try
            request = WebRequest.Create(forumInstance.loginUrl)
            setConnectionParameters(request)

            data = Encoding.ASCII.GetBytes(forumInstance.logindata)
            request.ContentLength = data.Length
            stream = request.GetRequestStream()
            stream.Write(data, 0, data.Length)
            stream.Flush()
            stream.Close()

            response = request.GetResponse()

            If forumInstance.isLoggedIn(cookies) Then
                Return True
            End If
        Catch ex As Exception
            'do something with the exception
        End Try
        Return False
    End Function

    Public Sub setConnectionParameters(ByRef request As HttpWebRequest)
        With request
            .Method = "POST"
            .Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
            .ContentType = "application/x-www-form-urlencoded"
            .Proxy = Nothing
            .CookieContainer = cookies
            .KeepAlive = True
            .ServicePoint.Expect100Continue = False
            .UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8) Gecko/20051111 Firefox/1.5; FBI-version/0.07"
            '.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate") if you want to speed up the steam reading (most boards support this)
        End With
    End Sub

    'this function not implemented, it is added to show how to link the cookies from the login
    Public Sub navTo()
        'Dim request As HttpWebRequest
        'request.CookieContainer = cookies
        'etcetc: you could set idletime, speed if you simultaniously want to fire requests, headers, method (get/post), etc
    End Sub

    'Note: to read the result in login()
    '--If you want to read the result (using compression techniques to speed it up--
    'Dim responseStream As IO.Stream = response.GetResponseStream()

    'If (response.ContentEncoding.ToLower().Contains("gzip")) Then
    '    responseStream = New GZipStream(responseStream, CompressionMode.Decompress)
    'ElseIf (response.ContentEncoding.ToLower().Contains("deflate")) Then
    '    responseStream = New DeflateStream(responseStream, CompressionMode.Decompress)
    'End If

    'Dim streamReader As IO.StreamReader = New IO.StreamReader(responseStream, Encoding.Default)
    'Dim result As String = streamReader.ReadToEnd().Trim()
    'streamReader.Close()
    '--
End Class
MyBB
Code: Select all
Imports System.Net

Public Class phpBB3

    Inherits Forum

    Public Sub New(ByVal url As String, ByVal username As String, ByVal password As String)
        MyBase.New(url, url & "/ucp.php?mode=login", username, "phpbb3_1fh61_u", "1", _
        "username=" + username + "&password=" + password + "&redirect=&sid=&redirect=&login=Login")
    End Sub

    Public Overrides Function isLoggedIn(ByVal cookies As System.Net.CookieContainer) As Boolean
        If Not cookies.GetCookies(New Uri(url)).Item(defaultCookieName).Value.Equals(defaultCookieSearch) Then
            Return True
        End If
        Return False
    End Function
End Class
Forum
Code: Select all
Public MustInherit Class Forum
    Private _logindata As String
    Private _loginUrl As String
    Private _url As String
    Private _username As String
    Private _defaultCookieName As String
    Private _defaultCookieSearch As String

    Public Sub New(ByVal url As String, ByVal loginUrl As String, ByVal username As String, ByVal cookieName As String, _
  ByVal cookieSearch As String, Optional ByVal data As String = "")
        Me._url = url
        Me.loginUrl = loginUrl
        Me.logindata = data
        Me.username = username
        Me._defaultCookieName = cookieName
        Me._defaultCookieSearch = cookieSearch
    End Sub

    Public MustOverride Function isLoggedIn(ByVal cookies As System.Net.CookieContainer) As Boolean

    Public Property logindata() As String
        Get
            Return Me._logindata
        End Get
        Set(ByVal value As String)
            Me._logindata = value
        End Set
    End Property

    Public Property url() As String
        Get
            Return Me._url
        End Get
        Set(ByVal value As String)
            Me._url = value
        End Set
    End Property
    Public Property loginUrl() As String
        Get
            Return Me._loginUrl
        End Get
        Set(ByVal value As String)
            Me._loginUrl = value
        End Set
    End Property

    Public Property username() As String
        Get
            Return Me._username
        End Get
        Set(ByVal value As String)
            Me._username = value
        End Set
    End Property
    Public Property defaultCookieName() As String
        Get
            Return Me._defaultCookieName
        End Get
        Set(ByVal value As String)
            Me._defaultCookieName = value
        End Set
    End Property
    Public Property defaultCookieSearch() As String
        Get
            Return Me._defaultCookieSearch
        End Get
        Set(ByVal value As String)
            Me._defaultCookieSearch = value
        End Set
    End Property
End Class
Regards
User avatar
pip
VIP - Donator
VIP - Donator
Posts: 156
Joined: Tue Jul 12, 2011 3:13 am

Re: Mybb,phpbb login in application!
pip
if you get the error msg it is basically glitchy it works and all the code looks right but it could be like a cookie/cache problem if you download ccleaner free and clear all temps and stuff i think you only get 1 chance to login as it might glitch. this is a problem i have not yet been able to solve or find solution to. and there might be newer versions of this coding somewere
<a href="http://www.points2shop.com/s/xbox_point ... 5082"><img src="http://points2shop.com/images/promotion ... ricoxg.gif" border="0"/></a>
5 posts Page 1 of 1
Return to “Tutorials”