For whom the tutorial is:
Well, I am sorry that this is not for beginners. I mean, when I started writing I thought I will explain each lines of code in this tutorial but, you know it’s impossible for me and I am sorry. So, if you are a complete beginner it will be hard for you to understand.
01. You should have knowledge about creating functions and their usages.
02. You should have knowledge about connecting MS Access Databases with VB.NET08.
03. You should have knowledge about SQL Queries.
04. You should have basic knowledge about the program structure of VB.NET08
Well, for your interest you can keep this tutorial, try to understand it. Read the following lines to understand what I have done in the code.
The Structure of Program:
Well, welcome to this tutorial where we will be building a form for the purpose of “Login of existing users and Registrations of new user”.
Following things we have to keep in our mind before we start. Actually this is the step called, Analyzing the Problem where we will find out smaller steps to complete, bricks of building.
01. The Form when loading will check the database to find out if there is an Administrator Account or Not.
If Found then ok
Else We will disable all features and force the user to create an Administrator account.
02. Well, if there is an Administrator account, then we will provide two options as radio buttons; Log-in and Registration. The log-in radio button will be selected by default.
03. When the Log-in radio button is selected there will be text box for user name and another for password.
04. When the Registration radio button is selected there will a text box for user name, another for password and another for the password of the administrator as we will not allow anyone to register who is not authenticated by the administrator.
05. Supposing log-in radio button is selected and user has provided username and password, then we will search the database for matching username and password as provided and if found the user will be logged in, otherwise not.
06. Supposing registration radio button is selected and user has provided username, password and administrator password. Then we will first check that if the given administrator password matches with the one we have in our database. If not matched, then exit. Else find that if we have the given username previously in our database or not. If found then promote the user to chose another user name, else complete the registration.
All right, that’s enough, lets get to work.
Database: Create a database in MS Access and name it ‘Master.mdb’. Create a table titled “login”. It will have the following fields and their data types,
Now create another table titled “logHistory”, which will keep the information about which user is logging at when. The logHistory will have following fields and data types
Now open up VS.NET08 and perform the following tasks
Text-Log In | Register
Text-The Main Form
Now take the following objects on the form ‘Login_Form’
Name = but_ok
Name = GroupBox1
Name = Lable1
AutoSize = False
[resize this Lable as I resized it which is given in the picture below, we will put our messages here, thus we need it a little bigger.]
Name = lab_userid
Text = User ID
Name = lab_admin_pass
Name = radio_login
Text = Log In
Name = radio_register
Text = Register
Name = tex_userid
Name = tex_userpassword
Name = tex_admin_pass
Name = DateTimePicker1
Visible = False
Name = DateTimePicker2
Visible = False
The interface of the Login_Form will now be something like that,
Now goto the menubar as select Project Menu, and then select the Last Item from the menu which is
“<Your_Project_Name> Properties”. In our case, if the project name is Tutorial01, then the item title will be “Tutorial01 Properties”. However you can open your Project’s Properties anyway, like from the solution manager etc.
Here Change the “Startup Object” to Mother_Form.
Hey, did you saved your project yet. Do it !!! It is better practice that you save your project after any little change you brought to it.
Ok now, go to the location where you have saved you project in your harddisk and find the folder named “Debug”. Move the database created earlier to here in this folder, “Debug”. We are doing this because in that way the .exe of our project and the database will stay together. So if we move them anywhere in the world, but keep them together, they will work, otherwise not as we will mention the location of the database to the software as it is in the location where the software is.
In the Code, I have putted enough comment so that you can understand. For now, Lets discuss a little. The Mother_Form will Load First and at its Load Event we will disable all its controls like MenuStrip, ToolStrip etc. Then We will load the login_Form as a Child Form of the Mother_Form. Ahh……I am too tired.
Look, any of you having any problem with understanding the code just put a comment here, I will try my best to explain what I have done in there. It is really hard to make someone understand, but I have tried a lot in the codes, and will also try here in the comments. Ok. Sorry for not explaining here.
I am sorry that before uploading I forgot to clear the database. You will need this password of administrator to register,
Admin Password : 007
Alternatively you open the database with MS Access and clear all data of the two tables login and logHistory.
[Download The Project File Along with Software and Database From Here]
Admin Password : 007
Limitations: The database is not password protected. So though you have passwords for your software, you dont have any for the keeper. I wish that in the next or upcoming tutorials I will explain you all about using password protected database files with your software.