Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to create authentication form? 1

Status
Not open for further replies.
May 22, 2006
16
MY
hi,

anyone know how to create authentication form by using vb.net with microsoft access databases?

So, each user will be depend on the username, password and access level to login to another related form.

Thanks!!

Regards,
charles
 
Hi,
First off all, the login form is actually included in .net for you! Right click in the "Sollution Explorer" -> Add -> New Item -> "Login Form".

After that is done, you have your login form, as far as basic GUI goes.

I generated some "tutorial code" for you:
Code:
Imports System.Data
Imports System.Data.OleDb
Public Class LoginForm1
    Dim mypath As String = Application.StartupPath & "\mydb.mdb"
    Dim mypassword As String = ""
    Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mypath & ";Jet OLEDB:Database Password=abc123" & mypassword)
    Dim cmd As OleDbCommand

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim sql As String = "SELECT username, password FROM users WHERE username='" & UsernameTextBox.Text & "' AND password='" & PasswordTextBox.Text & "'"

        cmd = New OleDbCommand(sql, conn)
        conn.Open()
        Dim dr As OleDbDataReader = cmd.ExecuteReader

        Try
            If dr.Read = False Then
                MessageBox.Show("Authentication failed...")
            Else
                MessageBox.Show("Login successfully...")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        conn.Close()

    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Private Sub LoginForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

I ran it and it worked here..
It might need a bunch of improvements, as far as security goes.. Take it as a simple example, not your final sollution.

Olav Alexander Mjelde
Admin & Webmaster
 
btw, adding userlevel is also quite easy..

I would make a seperate table for userlevels:
[userlevel_id] (autonumber)
[userlevel_title] (varchar(50))
etc. etc.

eg. if your different userlevels has different properties, as how much data they can store, you might add:
userlevel_storage_amount (int)

Then you want a 1:many relation on the users table and the userlevel table, so the fk would be a field "userlevel_id_id_userlevel_id" or something ,in the users table..

You would then generate a view in the access db and instead of running a query on a table, you run the query on the view.

You would also have to code in your application what the diffent users would be able to acces..

I would also store the login userlevel and username (not password) in global variables.

If using md5, etc. in the password, for "encryption", you also have to implement that on the password, before sending to the db for auth.
I'm not sure if Access has an md5 function.

Olav Alexander Mjelde
Admin & Webmaster
 
DaButcher - is the login form in 2003? It does not come up.
Thanks
djj
 

"is the login form in 2003? It does not come up"


The 2005 edition has a login form sample. I assume that the code by DaButcher is from VS 2005 because i dont see any inheritance statements (and ofcourse because he adds a login form which is a 2005 new item, lol). Generally:

Public Class LoginForm1
Inherits System.Windows.Forms.Form

' code
End Class
 
np charles.
Thank you for the star :)

Yeah, tipgiver, once again I assumed everyone had what I have :p I just started .net a week ago, or so, so I dont know that much about changes/updates and I'm still learning.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top