Page 1 of 2

Registration - Tutorial + Project Download

Posted: Mon Mar 01, 2010 3:45 am
by Livengood
*Make Sure that the user has no @gmail.com on it*
For Example :
i have a email at gmail - austinlivengood@gmail.com now what you do is you take the @gmail.com off
and the text that would be entered would just be austinlivengood

------------------------------------------------------------------------------------------------------------------------

ok well i am going to be showing you how to make a registration for your program, this has nothing to do with mysql and things. This is using a smtp. Its going to generate a key code for the use and most of the program will not be workable with out registration.
For Example :
Image

Main Form
Now for this the form load is, this code will check and see if the program has been registered
Code: Select all
If My.Settings.key = "" Then
Button2.Enabled = False
Else
If My.Settings.inkey = My.Settings.key Then
Button2.Enabled = True
Else
Button2.Enabled = False
End If
End If
Button 1 click: *Opens this registration form*
Code: Select all
Register.ShowDialog()
Button 2 click: *After Registration*
Code: Select all
NextForm.Show()
Me.Close()
Registration Form :
This is one of the most important forms to the program, because this will save the settings of the key code.
Image

ok so now one form load we its going to generate a random key code

Imports :
Code: Select all
Imports System.Net.Mail
Code: Select all
    Private Sub Register_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Random()
        If My.Settings.inkey = "" Then
        Else
            MsgBox("You have already registered!", MsgBoxStyle.Exclamation, Title:="Information")
            Me.Close()
        End If
        If My.Settings.key = "" Then
            Random()
            My.Settings.key = Label1.Text
            My.Settings.Save()
        End If
    End Sub
    Public Sub Random()
        If My.Settings.key = "" Then
        Else
            Dim Z As New Random
            Label1.Text = Z.Next(100000, 999999999)
        End If
    End Sub
this code will generate a key code and if you have already registered then it will open a message box saying so.

For Button 1 : i would like to give thanks to CodeNStuff for his wounderful coding on his email sender, i have used part of it to send out the email with the keycode. Thanks CodeNStuff cooll;

Button1 Click :
Code: Select all
        Dim username As String
        Dim password As String
        username = Convert.ToString(My.Settings.uname)
        password = Convert.ToString(My.Settings.pass)
        Dim from As New MailAddress(My.Settings.from)
        Dim [to] As New MailAddress(Me.TextBox3.Text)
        Dim theMailMessage As New MailMessage(from, [to])
        theMailMessage.Body = "Your Key is : " + My.Settings.key
        theMailMessage.Subject = "Registration Key Code"
        Dim theClient As New SmtpClient(My.Settings.server)
        theClient.UseDefaultCredentials = False
        Dim theCredential As New System.Net.NetworkCredential(username, password)
        theClient.Credentials = theCredential
        theClient.EnableSsl = True
        Try
            theClient.Send(theMailMessage)
        Catch wex As Net.WebException
        End Try
        MsgBox("Keycode Sent!", MsgBoxStyle.Exclamation, Title:="Information")
Button 2 Click :
this will check and see if the key code is correct or not.
Code: Select all
If TextBox2.Text = My.Settings.key Then
            My.Settings.inkey = TextBox2.Text
            My.Settings.Save()
            MsgBox("Sucess!", MsgBoxStyle.Information, Title:="Registered")
            Form1.Button2.Enabled = True
            Me.Close()
        Else
            MsgBox("Wrong Key Code", MsgBoxStyle.Exclamation, Title:="Error")
        End If

Settings :

Theses are the settings need in the project
Image

Project Download :
Registration - Tutorial.zip

Re: Registration - Tutorial + Project Download

Posted: Tue Mar 02, 2010 12:39 am
by alex6848
it doesn't work because email now reqiers ssl

Re: Registration - Tutorial + Project Download

Posted: Tue Mar 02, 2010 5:42 am
by Livengood
did you make sure that your username didnt have @gmail.com?

For example :
i have a email at gmail - austinlivengood@gmail.com now what you do is you take the @gmail.com off
and the text that would be entered would just be austinlivengood

Re: Registration - Tutorial + Project Download

Posted: Thu Mar 04, 2010 2:19 pm
by MiztaInsane
You most add this since you have ssl enable
Code: Select all
theClient.Port = 587

Re: Registration - Tutorial + Project Download

Posted: Sat Mar 06, 2010 2:29 am
by Livengood
it still sends without a port

Re: Registration - Tutorial + Project Download

Posted: Sat Apr 24, 2010 11:37 pm
by alex6848
dosn't work :(

Re: Registration - Tutorial + Project Download

Posted: Sun Apr 25, 2010 9:27 am
by Lewis
Changed the code a little bit and it worked :)

Re: Registration - Tutorial + Project Download

Posted: Mon May 24, 2010 8:51 pm
by XTechVB
alex6848 wrote:
it doesn't work because email now reqiers ssl
it works for me

Re: Registration - Tutorial + Project Download

Posted: Fri Jun 04, 2010 2:19 pm
by cvilanova
nice tut, i will use to my project in the university.. you are cool!! cooll;

Re: Registration - Tutorial + Project Download

Posted: Sat Jun 05, 2010 8:07 pm
by hungryhounduk
Hi Livengood
Great Tutorial, and it worked like a dream for me cooll;
all i had to do was change "SSL=TRUE" TO SSL=FALSE and then add my details and Voila!! :)

Nice one

Chris