Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > Visual Studio 2005
|
Visual Studio 2005 For discussing Visual Studio 2005. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2007, 10:33 AM
Registered User
 
Join Date: Aug 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to u_roc100@rediffmail.com
Default validation for user id & passwrod in vb.net

hello everybody,
i am have login form which is use to verify user name & password from
sql database
 below is my code for login button nut the problem is it is not
 verifying my password from database and simply giveing me msg
 invalid password. please help me to overcome this problem


 Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click

        Dim cnsql As SqlConnection
        Dim cmsql As New SqlCommand()
        Dim strsql As String

        Dim dr As SqlDataReader
        cnsql = New SqlConnection(connection)
        g_login = Me.txtuser.Text

        strsql = "select * from info_users where user_id = '" & g_login & "'"

        cmsql = New SqlCommand(strsql, cnsql)

        Dim valid As Boolean = False
        Dim hasrows As Boolean = False

        Dim strpassword As String = Me.txtpassword.Text
        If g_login = "" Then
            MessageBox.Show(" Cannot Be Blank ! ", "Login Form")
            Me.txtuser.Focus()
            Return
        End If


        Try
            cnsql.Open()
            dr = cmsql.ExecuteReader
            If dr.HasRows Then
                While dr.Read()

                    If strpassword = dr.Item("password") Then

                        valid = True

                    End If
                End While
                hasrows = True
                dr.Close()
            End If


        Catch exo As SqlException
            MsgBox(exo.Message)

        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            If cnsql.State = ConnectionState.Open Then
                cnsql.Close()

            End If
            cmsql = Nothing
            dr = Nothing
            cnsql.Dispose()
            GC.Collect()

        End Try

        icount = icount + 1
        If valid = True Then
            Me.Hide()
            ITEMS.Show()
        ElseIf icount = 3 Then
            MsgBox(" Contact Your System Administrator ")
            Me.txtuser.Focus()
            Me.txtuser.Text = ""
            Me.Close()
        Else
            MsgBox("Invalid Password")
            Me.txtpassword.Focus()
            Me.txtpassword.Text = ""

        End If
    End Sub

pls help me, by sending correct code to my Email Add : [email protected]



thank's in advance


 
Old August 6th, 2007, 10:17 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

Can you tell whether it is going in catch block or not.. If it is going in catch, what is the error??
 
Old August 6th, 2007, 03:12 PM
Registered User
 
Join Date: Aug 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to u_roc100@rediffmail.com
Default

Quote:
quote:Originally posted by gaurav_jain2403
 Can you tell whether it is going in catch block or not.. If it is going in catch, what is the error??

Mr. Gaurav thank for showing interest in my querry.
yes it is going in catch. if i shutdown my sqlserver then its is give me
error msg "Make sure your server is on" but i am not sure about the 2nd catch
block.
 
Old August 6th, 2007, 03:13 PM
Registered User
 
Join Date: Aug 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to u_roc100@rediffmail.com
Default

Quote:
quote:Originally posted by gaurav_jain2403
 Can you tell whether it is going in catch block or not.. If it is going in catch, what is the error??

Mr. Gaurav thank's for showing interest in my querry.
yes it is going in catch block. if i shutdown my sqlserver then its is giveing me
error msg "Make sure your server is on" but i am not sure about the 2nd catch block.

 
Old August 7th, 2007, 04:44 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

I have checked your code. It's fine as far as I think. Check the string you are using for Connection.

Add these two lines in your code:
 Dim g_login As String
 Dim connection As String = "server=ServerName;Database=DatabaseName;uid=??;pw d=??;"

Check your connection string.
 
Old August 7th, 2007, 04:46 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

One more thing, change your datareader loop to

           If dr.HasRows Then
                While dr.Read()

                    If strpassword = dr.Item("password") Then

                        valid = True

                    End If
                End While
                hasrows = True
            End If
            dr.Close()

DataReader should always be closed. It will increase your code efficiency.
 
Old August 12th, 2007, 11:19 AM
Registered User
 
Join Date: Aug 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to u_roc100@rediffmail.com
Default

Hi Gaurav,

 still it is not wroking man. suggest me some alternate code.

thank's







Similar Threads
Thread Thread Starter Forum Replies Last Post
autocomplete dropdownlistASP.NET 2.0 & VB.NET 2005 alexdcosta ASP.NET 2.0 Professional 10 May 11th, 2009 02:21 AM
Session ID swapping from user to user... greenwar VS.NET 2002/2003 3 September 7th, 2007 08:44 AM
Master pages &server control ID - asp.net 2.0 tech user C# 2005 1 August 3rd, 2006 04:31 AM
User ID Validation Ramakrishna ADO.NET 3 November 30th, 2004 07:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.