.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Articles >> General >> Post New Resource Bookmark and Share   

 Subscribe to Articles

A Simple Way To Use Authenticate Users

Posted By:Hefin Dsouza       Posted Date: August 13, 2009    Points: 25    Category: General    URL: http://www.dotnetspark.com  

Hi My Name is Hefin Dsouza.
From the very beginning i was in search for a simple way to authenticate users from a database there were many ways to do it.
But all very complex so I was researching for a simple trick to complete my task and here it is.
The Trick goes like this.
Problem : I want to Authenticate username and passwords from users using VB.net where the user names and passwords are stored in the database.

Solution : Create a table with the username and password column add some details and save the table.

Now come the interesting part of connecting your application to your database and validate the Logins

In your login form where you may have two textbox's for username and password.

On The Login buttons Click Event Write the Following Code.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tex As String = "select * from login where username='" + TextBox1.Text + "' and [password]='" + TextBox2.Text + "'"
dataAdap = New OleDbDataAdapter(tex, dataCon)
If dTable.Rows.Count <> 0 Then
MsgBox("Login Successfull", MsgBoxStyle.Information, "Login")
MsgBox("Login UnSuccessfull", MsgBoxStyle.Critical, "Login")
End If
End Sub

That's it And All Work Done and a Simple Login Box is ready to use.

This is a Simple way to Authenticate users in your application in a quick way.

If You have a better code please let me know.

Hefin Dsouza
 Subscribe to Articles


Further Readings:

Author: Syed Shakeer Hussain         Company URL: http://www.dotnetspark.com
Posted Date: August 15, 2009

Hi Hefin
You can do the same thing by usign SqlDataReader as follows.

SqlCommand cmd=new SqlCommand("Select username from tablename where username='"
SqlDataReader reader=cmd.ExecuteReader();
MsgBox("Login Successfull");
MsgBox("Invalid username");

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend