Super Complex vb.net server side registeration!

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

Hello CNS members here is a new tutorial on something i recently learned from a friend 85% credits to him 15% to me for changing language and few things. This is not the most secure way but it is a good way to make it more secure you might try to make it pdo the good thing about this is it is server sided the code cant be seen/edited!!!!

You also need dotnetbar for this if you don't have then buy it or find it somewhere free xD or pm me lol!

Note: Were it says Private Sub office2007StartButton1_Click(sender As System.Object, e As System.EventArgs) Handles office2007StartButton1.Click in registerform it is part of dotnetbar you can use a button or whatever also!!


Edit: this line of code is what connects the php to vb.net Public Shared BaseURL As String = "site to php files"
so like if you upload the php files to x10hosting or 000webhost or whatever put link like mysite.com/whatever to get to php files then it reads logster.php on register click so it reads inside, and connects to the database by the info you put. db user db pass db host. after that you also put site in php files link to php files on site at top were it says. then you take the sql file and import the database stuff which tracks the register part after logster and the login uses main.php. This is the reason to make it pdo is if your gonna make something were you want to charge people on it for like services or membership! here is pdo reference guide: http://php.net/manual/en/book.pdo.php
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
You need these 2 php files and 1 database dump to import into the mysql:
files.rar

next add 3 classes to vb.net project:
Functions
Capcha
UserInfo

also import Devcomponents.DotNetBar2.dll as a reference

Functions.vb code:
Code: Select all
Imports System.Security.Cryptography
Imports System.Text
Public Class Functions
    Public Shared Function Base64enc(input As String) As String
        Return Convert.ToBase64String(Encoding.UTF8.GetBytes(input))
    End Function

    Public Shared Function Base64dec(str As String) As String
        Dim decbuff As Byte() = Convert.FromBase64String(str)
        Return Encoding.UTF8.GetString(decbuff)
    End Function

    Public Shared Function MD5(input As String) As String
        Dim hashValue As Byte()
        Dim message As Byte() = Encoding.ASCII.GetBytes(input)
        Dim hashString As MD5 = New MD5CryptoServiceProvider()
        Dim hex As String = ""
        hashValue = hashString.ComputeHash(message)
        For Each x As Byte In hashValue
            hex += [String].Format("{0:x2}", x)
        Next
        Return hex
    End Function
End Class
Capcha.vb code:
Code: Select all
Imports System.Text
Public Class Capcha
    Private Shared SBuilder As New StringBuilder()
#Region ".: CAPTCHA Drawing :."

    Private Shared DrawingFont As New Font("Verdana", 20)
    Private Shared CaptchaImage As New Bitmap(220, 63)

    Private Shared CaptchaGraphic As Graphics = Graphics.FromImage(CaptchaImage)

    Private Shared Ran As New Random()
    Private Shared Alphabet As String() = {"A", "B", "C", "D", "E", "F", _
     "G", "H", "I", "J", "K", "L", _
     "M", "N", "O", "P", "Q", "R", _
     "S", "T", "U", "V", "W", "X", _
     "Y", "Z"}

    Public Shared Function GenerateCaptcha() As Bitmap
        SBuilder.Clear()

        For I As Integer = 0 To 4
            SBuilder.Append(Alphabet(Ran.[Next](0, Alphabet.Length)))
        Next

        Dim Rect As New Rectangle(0, 0, 220, 63)
        Dim StringFormat As New StringFormat()
        StringFormat.Alignment = StringAlignment.Center
        StringFormat.LineAlignment = StringAlignment.Center

        CaptchaGraphic.Clear(Color.White)
        CaptchaGraphic.DrawString(SBuilder.ToString(), DrawingFont, Brushes.Black, Rect, StringFormat)
        Return CaptchaImage

    End Function
#End Region

#Region ".: CAPTCHA Handling :."

    Public Shared Function IsValidCaptcha(Input As String) As [Boolean]
        If Input = SBuilder.ToString() Then
            Return True
        End If
        Return False
    End Function
#End Region
End Class
UserInfo,vb:
Code: Select all
Public Class UserInfo
    Private _id As String
    Private _user As String
    Private _groupId As String
    Private _profileImg As String
    Private _registerDate As String
    Private _Banned As String
    Public Sub New()
        Me.id = _id
        Me.user = _user
        Me.groupId = _groupId
        Me.profileImg = _profileImg
        Me.registerDate = _registerDate
        Me.banned = _Banned
    End Sub
    Public Property id() As String
        Get
            Return _id
        End Get
        Set(value As String)
            _id = value
        End Set
    End Property
    Public Property user() As String
        Get
            Return _user
        End Get
        Set(value As String)
            _user = value
        End Set
    End Property
    Public Property groupId() As String
        Get
            Return _groupId
        End Get
        Set(value As String)
            _groupId = value
        End Set
    End Property
    Public Property profileImg() As String
        Get
            Return _profileImg
        End Get
        Set(value As String)
            _profileImg = value
        End Set
    End Property
    Public Property registerDate() As String
        Get
            Return _registerDate
        End Get
        Set(value As String)
            _registerDate = value
        End Set
    End Property
    Public Property banned() As String
        Get
            Return _Banned
        End Get
        Set(value As String)
            _Banned = value
        End Set
    End Property
End Class
Form1 code:
Code: Select all
Imports System.Net
Imports System.Xml
Imports DevComponents.DotNetBar
Public Class Form1
    Private Shared client As New WebClient()
    Private UsrInfo As New UserInfo()
    Private loggedin As Boolean = False
    Public Shared BaseURL As String = "site to php files"
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If Not (txtUser.Text = "" AndAlso txtPass.Text = "") Then
            Dim query As String = String.Format(BaseURL & "logster.php?do=l&u={0}&p={1}", Functions.Base64enc(txtUser.Text), Functions.Base64enc(txtPass.Text))
            Dim SL As New XmlDocument()
            SL.Load(query)
            Dim valid As String = SL.SelectSingleNode("UserInfo/Result").InnerText
            If valid = "true" Then
                UsrInfo.id = SL.SelectSingleNode("UserInfo/ID").InnerText
                UsrInfo.user = SL.SelectSingleNode("UserInfo/Username").InnerText
                Label3.Text = UsrInfo.user
                Label3.Refresh()
                txtPass.Clear()
                txtUser.Enabled = False
                txtPass.Enabled = False
                loggedin = True
                me.hide
                mainfrm.show
            Else
                MessageBoxEx.EnableGlass = False
                MessageBoxEx.Show(valid, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
            End If
        End If
    End Sub
 Private Sub LinkLabel2_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
        registerformShow()
    End Sub
end class
registerform code:
Code: Select all
Imports System.Net
Imports DevComponents.DotNetBar.Controls
Imports DevComponents.DotNetBar
Imports DevComponents.DotNetBar.Controls.TextBoxX
Public Class regme
    Private Shared client As New WebClient()
    Private Sub textBoxX1_TextChanged(sender As Object, e As EventArgs) Handles Me.TextChanged
        Me.textBoxX1.Text = Me.textBoxX1.Text.ToUpper()
        Me.textBoxX1.SelectionStart = Me.textBoxX1.Text.Length
    End Sub
    Private Sub regme_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        pictureBox1.Image = Capcha.GenerateCaptcha()
    End Sub
    Private Sub office2007StartButton1_Click(sender As System.Object, e As System.EventArgs) Handles office2007StartButton1.Click
        If txtPass.Text = txtCpass.Text Then
            If Capcha.IsValidCaptcha(textBoxX1.Text) = True Then
                Dim query As String = String.Format(Form1.BaseURL + "logster.php?do=r&u={0}&p={1}&e={2}", Functions.Base64enc(txtUser.Text), Functions.Base64enc(txtPass.Text), Functions.Base64enc(txtEmail.Text))
                MessageBoxEx.EnableGlass = False
                MessageBoxEx.Show(client.DownloadString(query), "Register", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
            Else
                MessageBoxEx.EnableGlass = False
                MessageBoxEx.Show("Error, Wrong captcha", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
            End If
            pictureBox1.Image = Capcha.GenerateCaptcha()
        Else
            MessageBoxEx.EnableGlass = False
            MessageBoxEx.Show("Error, The passwords do not match", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
        End If
        Me.Hide()
    End Sub
    Private Sub buttonX1_Click(sender As System.Object, e As System.EventArgs) Handles buttonX1.Click
        pictureBox1.Image = Capcha.GenerateCaptcha()
    End Sub
End Class
That's all i think kinda tired as i wrote this thanks for reading and hope it is useful!

My Result :) : Image
You do not have the required permissions to view the files attached to this post.
Last edited by pip on Sat Aug 04, 2012 4:42 pm, edited 1 time 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
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

wow ! Nice tutorial , keep it up #pip
Find my programs on Softpedia
User avatar
pip
VIP - Donator
VIP - Donator
Posts: 156
Joined: Tue Jul 12, 2011 3:13 am

If anyone gets this to work let me know :) there is a error logging in like to many handles or something but the register part and database works + sends activate account to email entered!
<a href="http://www.points2shop.com/s/xbox_point ... 5082"><img src="http://points2shop.com/images/promotion ... ricoxg.gif" border="0"/></a>
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

I think you could have explained more of the code, including the server code, but nice done :)
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
pip
VIP - Donator
VIP - Donator
Posts: 156
Joined: Tue Jul 12, 2011 3:13 am

MrAksel wrote:
I think you could have explained more of the code, including the server code, but nice done :)
#MrAksel What server code the php files? they are self explanatory i would think people would know to put the database connection stuff and link to php files were it says then in code you baseurl + logster.php?=do.... then it goes to baseurl were it finds php files! if no one knew that now you do :) + if anyone needs help pm me if you want!




Note: also MrAksel if you can get the register to work can you test this, and try the login i get some error with to many handlers like the register works but not login part
<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”