473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

I want to create a login form in vb.net using the ms access as a backend tool

Ajay Bhalala
119 64KB
I am new here and
I am beginner in vb.net and I use the Ms Access as a backend tool.

I want to create a user loin form. I created the the form that have 1 combobox from that the user can select the username and 1 textbox in which user can enter the password for the selected username.

How to check the user enter the correct password for the selected username? on button click.
If the user enter the correct password for the selected username then the form1 should be open, and if wrong then msgbox should be open "Enter correct password."
How can i do this?

Can anyone help me on this? I tried lots but I can't do this.
Nov 12 '14 #1
4 6760
Frinavale
9,735 Expert Mod 8TB
Well, to answer this question we would have to take a look at your current design.

What does your data table for user information contain?

What I have typically done to accomplish this is have a table called something like "user" or "identity" or something and it contains the following columns:
  • ID: some sort of identifier that can be used to identify the user
  • User name: typically characters
  • Password: a security "hash" that was generated based on the password provided by the user and the salt randomly generated so that the database never contains passwords
  • Salt: the key used to generate the password hash

To generate the salts and passwords that are stored in the database the controls and methods that are part of the System.Security.Cryptography namespace are used.

For example, the following would generate a salt to be used:
Expand|Select|Wrap|Line Numbers
  1. Public Function GetSalt() as String
  2.   Dim saltSize = 32
  3.   Dim salt As RNGCryptoServiceProvider = New RNGCryptoServiceProvider()
  4.   Dim randomBytes(saltSize - 1) As Byte
  5.   salt.GetBytes(randomBytes)
  6.   Return Convert.ToBase64String(randomBytes)
  7. End Function
And the following would generate the password hash using the SHA512 algorithm that is stored in the database:
Expand|Select|Wrap|Line Numbers
  1. Public Function HashedPassword(Byval salt as String, ByVal providedPassword As String) As String
  2.   Dim passWithSalt =  String.Concat(salt, providedPassword)
  3.   Dim rawPasswordData() As Byte = Encoding.UTF8.GetBytes(passWithSalt)
  4.   Dim sha As New SHA1CryptoServiceProvider()
  5.   Dim reslutingHash As Byte() = sha.ComputeHash(rawPasswordData)
  6.   Return Convert.ToBase64String(reslutingHash)
  7. End Function
  8.  
Now the thing is that the database has to be populated with user names, salts and passwords using the above functions in order for the rest of this to work...

Once you have populated your user table with the salt and password hashes using the above functions, all you have to do upon logging in is:
  • perform a database query that selects the user record from the database with the User Name (or User ID) that the user selected from the combobox
  • if a row was returned, retrieve the salt from the "salt" column and the hashed password from the "password" column
    • (if no row was returned then no user with that user name exists)
  • retrieve what the user entered as a password
  • execute the HashedPassword method with the salt from the database and the password-string that the user provided
  • compare the password hash generated based on what the user provided against the password has retrieved from record ...
    • if they match then they are authenticated and can log in
    • if they don't match then the user did not provide the correct password
Nov 12 '14 #2
Ajay Bhalala
119 64KB
Thank you for help.

But I am SY B.Sc.IT student and I don't know more about the vb.net.

I don't know about the HashPassword Method or salt so if another simple way is possible then please told me.

I want to do as follows..
• user have to select the username from the combobox
• and enter the password into the Textbox
• Then by clicking the "Login" button, the new form should be open if the user enter the correct password for the selected username.

I write the code as follows...
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.OleDb
  2.  
  3. Public Class Login
  4.  
  5.     Public con As New OleDbConnection("Provider=microsoft.jet.oledb.4.0 ; Data Source=E:\Brinda & Jay\Brinda\02 S.Y\VB.NET\My Project\Project.mdb")
  6.     Public qry As String
  7.     Public dr As OleDbDataReader
  8.  
  9.  Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  10.         Me.fillcombo()
  11.     End Sub
  12.  
  13.     Sub fillcombo()
  14.         con.Open()
  15.         qry = "select * from UserAccount"
  16.         Dim cmd As New OleDb.OleDbCommand
  17.         cmd.CommandText = qry
  18.         cmd.Connection = con
  19.         dr = cmd.ExecuteReader
  20.         While (dr.Read())
  21.             ComboBox1.Items.Add(dr("UserName"))
  22.         End While
  23.         cmd.Dispose()
  24.         dr.Close()
  25.         con.Close()
  26.     End Sub
  27.  
  28.     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  29.         con.Open()
  30.         qry = "select * from UserAccount where UserName=' " & ComboBox1.Text & " ' "
  31.         Dim cmd As New OleDbCommand
  32.         cmd.CommandText = qry
  33.         cmd.Connection = con
  34.         dr = cmd.ExecuteReader()
  35.         If (dr.Read() = True) Then
  36.             TextBox2.Text = dr("Password")
  37.             'MsgBox("Access")
  38.             'Else
  39.             'MsgBox("No Access Authorized!")
  40.         End If
  41.         cmd.Dispose()
  42.         con.Close()
  43.     End Sub
  44. End Class
  45.  
Please help me on this and say what changes I have to made in this code?
Nov 13 '14 #3
Frinavale
9,735 Expert Mod 8TB
If password security is not a concern because this is a simple project for school then you don't need to worry about password hashes.

However, in the real world it is a VERY terrible idea to store the user's password, as they entered it, into the database as plain text.

To fix that, what is typically stored is a random string that is generated using a cryptography hashing method based on the value that the user entered. The hashing method that I used as an example was the SHA1 algorithm; however, there are several methods available for you to use.

To increase security a little more, salts are used along with the hashing method....


Anyways, it seems like you are just storing plain text so we will continue on that bases...

It may help if you added a button that the user can click to "log-in" after they have finished providing a password.


Then take what you have in this method:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
And move it to the button click event. Then modify that method to get the text provided by the user and compare it against the password field retrieved from the database for the user.

-Frinny
Nov 13 '14 #4
Ajay Bhalala
119 64KB
Thank you so much for the help. It is very useful for me.
Nov 13 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rudi Groenewald | last post by:
Hi there... I use SQL server integrated security so when a user opens a database in access it prompts the username & password in a small popup box on connection, but I'd like to use my own...
7
by: Nerrad | last post by:
Hi, i am currently working on a project which requires me to create a form to allow the user to change their password. I know there is a user-level security login which is easier and safer but...
13
by: knot2afrayed | last post by:
I am trying to fix error- object does not exist- I want it possible to allow object not to exist. I am writing a script on a page that may or may not include a login form. For example-after a...
4
by: John Devlon | last post by:
Hi, I'm trying to create a login page using the default login controle. I also would like to use a custom Ms Acces database instead of a sql server database. Can anyone please tell me how to...
1
by: keirnus | last post by:
Hello, I'm really new to this "graph" stuff. I couldn't google the topics regarding the creation of Graph in Excel using Access VBA...Dunno where to start. (huhuhu) What I only know is...
3
meenesh
by: meenesh | last post by:
related to above question please help me out :-- on the basis of above interact with database i also want some animated output to appear such as "smile should increase if student secure above 90...
4
by: Kelly Warden | last post by:
I want to create a form in Access to update my table automatically with the information selected from combo boxes, lists, comments, etc. Also, I want to automate this w/ some VBA or SQL or...
37
ashjones86
by: ashjones86 | last post by:
Hi All, So im looking for some help with access 2007 if at all possible. I am new to access as work has asked me to create a database, so the database side to it i have sorted i.e inputting data...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.