2 Replies - 655 Views - Last Post: 03 February 2010 - 09:18 AM Rate Topic: -----

#1 newcoder2010  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-January 10

Login code is not working properly

Posted 29 January 2010 - 02:50 AM

Hi! I am not here for doing my school project! I am learning programming & thats why I need help. I have tried to make a program in Visual Basic 6 where login leads an important role. Main interface has two text box & one command button. I have connected those text boxes with SQL Server 2000. However when user will input right user name & password then he or she will get permission to access next form. Here is the example of my code.

Module - Public con As New ADODB.Connection
Public rst As New ADODB.Recordset

Command button1- Private Sub Command1_Click()
On Error Resume Next
Set con = New ADODB.Connection
con.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=test"
Dim convt As String
convt = UCase(Text1.Text)
Set rst = New ADODB.Recordset
With rst
.Open "Select * from sec_info", con, adOpenKeyset, adLockOptimistic
If Text1.Text = !user_name Then
ElseIf Text2.Text = !user_pass Then
MsgBox "Welcome!", vbInformation
Else: MsgBox "Wrong user name!", vbCritical
End If
.Close
End With
End Sub

But it didnt work. If I store more than one user name & password then it doesnt work. As a result I wrote -

Private Sub Command1_Click()
On Error Resume Next
Set con = New ADODB.Connection
con.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=test"
Dim convt As String
convt = UCase(Text1.Text)
Set rst = New ADODB.Recordset
With rst
.Open "Select * from sec_info where user_name = '" & Text1.Text & "' And user_pass = '" & Text2.Text & "'", con, adOpenKeyset, adLockOptimistic
If Text1.Text = !user_name Then
ElseIf Text2.Text = !user_pass Then
MsgBox "Welcome!", vbInformation
Else: MsgBox "Wrong user name!", vbCritical
End If
.Close
End With
End Sub


But still same its not working. It gets first user from database but it doesnt get another users. I guess I have to use loop sense so that it will get all users by looping it again & again. Please help me as early as possible.

*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 29 January 2010 - 06:29 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Login code is not working properly

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Login code is not working properly

Posted 29 January 2010 - 06:12 AM

hello :)

when you make a query to your DB to check user name and password try this
With rst
.Open "Select * from sec_info where user_name = '" & Text1.Text & "' And user_pass = '" & Text2.Text & "'", con, adOpenKeyset, adLockOptimistic
If .Recordcount<>0 Then
MsgBox "Welcome!", vbInformation
Else: MsgBox "Wrong user name or password!", vbCritical
End If
.Close
End With



you make a query and then check if there is any records about it. if not then the user name or password is wrong. the way your code looks now it will return 0 for recordcount if some of them is wrong then fields user name and password will be empty. so in short just check if there is a such record to verify if the username and password are correct :)

good luck dude :)
Was This Post Helpful? 0
  • +
  • -

#3 MikeGreat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-February 10

Re: Login code is not working properly

Posted 03 February 2010 - 09:18 AM

"Select * from sec_info
try this code

with rst
.open "Select * from Sec_info", con
if .eof then
.close
exit sub
end if
.movefirst
if text1.text = !user_name and text2.text = !user_pass then
msgbox "Welcome"
else
msgbox "Wrong username and/or password"

end if
.close
end with



please let me know if it is working... gudluck

This post has been edited by MikeGreat: 03 February 2010 - 09:21 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1