473,394 Members | 1,852 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,394 software developers and data experts.

Login Authentication in vb.net

Hi Team,

Below code is working fine. Main thing is if i entered wrong username and password it was not displaying message MsgBox("invalid username or password"). please help ow to validate it using sql. what is going wrong. thanks in advance.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Try
  3.             con.Open()
  4.             cmd.CommandType = CommandType.Text
  5.             cmd.CommandText = "select * from login where username in('" & TextBox1.Text & "')and password='" & TextBox2.Text & "'"
  6.             da = New SqlDataAdapter(cmd.CommandText, con)
  7.             da.Fill(ds, "login")
  8.             maxcount = ds.Tables(0).Rows.Count - 1
  9.             Dim a(maxcount), b(maxcount) As String
  10.                         For i = 0 To maxcount
  11.                 a(i) = ds.Tables("login").Rows(i).Item(0)
  12.                 b(i) = ds.Tables("login").Rows(i).Item(1)
  13.                 If a(i) = TextBox1.Text And b(i) = TextBox2.Text Then
  14.                     Me.Hide()
  15.                     Form2.Show()
  16.                 Else
  17.                     MsgBox("invalid username or password")
  18.                 End If
  19.  
  20.             Next
  21.  
  22.         Catch ex As Exception
  23.             MsgBox(ex.Message.ToString)
  24.         End Try
  25.         con.Close()
  26.     End Sub
May 5 '10 #1
4 3860
Monomachus
127 Expert 100+
@krisssgopi
Hi,
First of all don't ever build a query this way, it can cause users cracking your application using SQL injection. Instead use SqlParameter. Take a look at this lesson Lesson 06: Adding Parameters to Commands.

2. I don't think your sql request is right "username in('" + TextBox1.Text + "')". If you want to login, I think you should change it to username = '" + TextBox1.Text + "'. Sorry databases is not my strongest side.

3. I don't really understand what are you trying to do.
Please explain.
Expand|Select|Wrap|Line Numbers
  1. maxcount = ds.Tables(0).Rows.Count - 1
  2. Dim a(maxcount), b(maxcount) As String
  3. For i = 0 To maxcount
  4. a(i) = ds.Tables("login").Rows(i).Item(0)
  5. b(i) = ds.Tables("login").Rows(i).Item(1)
  6.  
P.S. You still don't use code button. Please use code button(#) or tags to insert the code. Thanks in advance

May 5 '10 #2
@Monomachus
Hi Buddy,
1.) select * from student where username in('gopi') we can query like this way also na.
2.)What i am trying is... getting the username and password in textbox. comparing those thing in database if it is correct it should show me form2 otherwise i has to display me the message.
3.)
For i = 0 To maxcount
a(i) = ds.Tables("login").Rows(i).Item(0)
b(i) = ds.Tables("login").Rows(i).Item(1)
If a(i) = TextBox1.Text And b(i) = TextBox2.Text Then
Me.Hide()
Form2.Show()
Else
MsgBox("invalid username or password")
End If

i am making the loop this array will hold the record of username and password. this will check with the value entered by user in textbox 1 and 2.

Please help me...give me idea to develope this application.
May 5 '10 #3
Monomachus
127 Expert 100+
@krisssgopi
You don't need all these. All you need is just execute SQL
"select * from login where username = '" & txtUsername.Text & "' and password='" & txtPassword.Text &"'.
And than if select returns something (it only can be your user), than you have a user with such a username & password. If not when you show the messagebox ("invalid username or password").

P.S. I'm not gonna help you if you don't read the links that I give you.
May 5 '10 #4
tlhintoq
3,525 Expert 2GB
TIP: When you first created your question you were asked to wrap your code with [code] tags.

It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it.

More on tags. They're cool. Check'em out.
May 5 '10 #5

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

Similar topics

3
by: janet | last post by:
hI ... I am newbie to ASP ... i am trying to write a code to accept login and passwor from a user and verify through a table created in MySQL. I am just trying to write a code on my own...
2
by: NickyW | last post by:
Hi, Can anyone help. I have a folder on my website that has 'anonymous access' and 'basic authentication' disabled, and requires 'intergrated Windows authentication'. This used to work fine, but...
4
by: nicholas | last post by:
Hi, Got an asp.net application and I use the "forms" authentication mode defined in the web.config file. Everything works fine. But now I would like to add a second, different login page for...
2
by: Assimalyst | last post by:
Hi, I am creating a website where i want to allow some webforms to be accessible to all users, and those in a subdirectory available only to authenticated users. I have created a script to...
3
by: | last post by:
One thing I did a lot of in Classic ASP involved showing page elements conditionally based on whether a user was logged in or not. Logged in users or "superusers" would get more content and/or more...
1
by: lucifer | last post by:
i want to use windows login authentication in my application can some body tell me how to do it.
7
by: Nick | last post by:
Platform: Visual Studio 2003 Language: C# NOTES: 1. Application will need to run on Windows 2000, Windows 2003, Windows XP 2. Client machines will be standalone NOT part of a domain. 3. I...
5
by: libra786 | last post by:
I have created a blog and have added a login box which prompts the user for login and id before posting- The username and password have been stored in the database, however when i enter the username...
1
by: tanya.wang | last post by:
Hi all, We have a site called http://www.mydomainxyz.com/ and our network guy has set up load balancing with multiple IIS servers. We also have a function that allows users to upload photos on...
2
by: ragunit1983 | last post by:
Hi, Please share your ideas about, How to implement windows NT login authentication in php.. i need to pull the windows NT login username to my php application i have tried some php...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.