Within this 3 part tutorial I am going to show you how to program a user login complete with database, admin user interface and a privilege system.
Many people program very simple login systems along the lines of an if statement or two, this is good if you have one or two users but what if you have 15 users using an application and your always adding more; relaying on an if statement is just out of the question because when you add a new user you would have to recompile the application and deploy it every time. This is why we use a database to store our username’s and password’s because to add a new user all you have to do is add the user into the database and your done.
For this tutorial we are going to use
Visual Basic 2008 (.net 3.5 however .net 4.0 MAY work, have not tested)
SQL server 2008 R2 Express edition.
2) The database
For this whole tutorial we are going to be using Microsoft SQL studio and database engine, if you have not done so allready and installed please see this post on how to install SQL studio.
First of start by connecting to your SQL server, in my case my “server name” is “JACK-PC\SQLSERVER” (without quotes). Expand the “databases” section under object explorer, right click on the “databases” tree you just expanded and select “New Database”. Enter a database name, for this instance we are going to call it “Login” (without quotes).
Now under “Databases” you should have your new Login database. Click on it and expand it, there should be a “Tables” sub tree. Right click the “Tables” sub tree and click “New table”. You should have a window similar to fig 2 and fill out according to fig 2
1) Set the ID colum to primary key (number 2) and (is identity) = yes (Number 3)
2) Create all the other colums and set them to: Username = varchar(50), Password = varchar(50), Privilege = int.
3) Give the table the name “Users” (number 4) and save: File > save all.
There we go, you have created the database, please see part 2 for “logging in”.