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

User name and password validation

Please could some one provide me the code to validate the user name and password fields using Vb for MS access.

Fields ::
User name :: text box
Password :: text box
Login :: button

The form should accept the user name and password from the text box , validate the same against a table on MS access if successful should allow the user to proceed to next form else display a alert/error message.


Thanks a lot,
Mithun.
Sep 20 '07 #1
14 7337
debasisdas
8,127 Expert 4TB
Kindly post the code that you have tried to solve this problem, to get help from our experts
Sep 20 '07 #2
Code containing errors
Expand|Select|Wrap|Line Numbers
  1. Private Sub Login1_Click()
  2. On Error GoTo Err_Login1_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.     text3.SetFocus
  7.  
  8.     If text3.Text = user_validate.user_name And text5.Text = user_validate.Password Then
  9.  
  10.     stDocName = "Applications"
  11.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  12.     Else
  13.     MsgBox "Please enter correct user name and password", vbOKOnly
  14.  
  15.  
  16. Exit_Login1_Click:
  17.     Exit Sub
  18.  
  19. Err_Login1_Click:
  20.     MsgBox Err.Description
  21.     Resume Exit_Login1_Click
  22.     End If
  23. End Sub
Sep 20 '07 #3
QVeen72
1,445 Expert 1GB
Hi,

Remove the error handling and keep a break point and tell us which line u r getting the error...?

What is this :
user_validate.user_name
(TableName.FieldName) or (FormName.ControlName)... ?


REgards
Veena
Sep 20 '07 #4
how secure are you wanting this to be you may want to consider some encrytion as the password and username can easly be retrived by a hex editor this way
Sep 20 '07 #5
Hi,

Remove the error handling and keep a break point and tell us which line u r getting the error...?

What is this :
user_validate.user_name
(TableName.FieldName) or (FormName.ControlName)... ?


REgards
Veena

user_validate.user_name
(TableName.FieldName)
Sep 20 '07 #6
QVeen72
1,445 Expert 1GB
Hi,

Then, u simply cant give, TableName.FieldName,
U have to declare a Record set Open Recordset with the "Where Crieteria", if u find any Records, then allow to proceed or else, Prompt again, giving appropriate message . SQL Statement shud be something like this :

Expand|Select|Wrap|Line Numbers
  1. sSQL = "Select * From UserTable Where UserName = '" & TxtUserName.Text & "' And Password = '" & txtpwd.text & "'"
  2.  
Regards
Veena
Sep 20 '07 #7
Trying with the following code....
getting an error as "Object required"

* * * code * * *

Expand|Select|Wrap|Line Numbers
  1. Private Sub Login_Click()
  2. On Error GoTo Err_Login_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.     Dim user_name As String
  7.     Dim passwor As String
  8.  
  9.  
  10. If user_validate.user_name = Text3.Text And user_validate.Password = Text5.Text Then
  11. sSQL = "Select * From User_validate Where User_Name = '" & Text3.Text & "' And Password = '" & Text5.Text & "'"
  12.  
  13.     stDocName = "Applications"
  14.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  15.  
  16.     Else
  17.     MsgBox "Invalid user id or password, please try again", vbOKOnly
  18.  
  19.  
  20.  
  21. Exit_Login_Click:
  22.     Exit Sub
  23.  
  24. Err_Login_Click:
  25.     MsgBox Err.Description
  26.     Resume Exit_Login_Click
  27.     End If
  28.  
  29. End Sub
Sep 20 '07 #8
QVeen72
1,445 Expert 1GB
Hi Mithun,

Open a Recordset with the given SQL Statement, in ur code, open recordset line is missing..

REgards
Veena
Sep 20 '07 #9
Hi Mithun,

Open a Recordset with the given SQL Statement, in ur code, open recordset line is missing..

REgards
Veena

Hi Veena,
I'm a begineer with VB. Please could you let me know how i can Open a Recordset with the given SQL Statement.
Thanks a lot for the guidance and support.
regards,
Mithun
Sep 20 '07 #10
QVeen72
1,445 Expert 1GB
Hi,

I have not used mucg of VBA, I always work on VB6,
Anyway, Check This Basic Code:
I assume u r using ADO

Expand|Select|Wrap|Line Numbers
  1. Dim rs As ADODB.Recordset
  2. Dim sSQL As String
  3. Set rs = New ADODB.Recordset
  4. sSQL ="Select * From MyUserTable Where UserName = '" _
  5.     & Trim(txtUserName.Text) & "' And Pwd ='" & Trim(txtPwd.Text) & "'"
  6. rs.Open sSQL, CurrentProject.Connection
  7. If RS.EOF Then
  8.    Msgbox "User Not Found"
  9.    'Prompt again for user name /pwd
  10. Else
  11.    'User Found
  12.    'Write Code to Open ur Application
  13. End If
  14. rs.Close
  15. Set rs = Nothing
  16.  
  17.  
U can refine the Code..

REgards
Veena
Sep 21 '07 #11
Hi Veena,
Thanks a lot for the help and guidance.....
I have a question with regards to setting the focus on an object "
Please could you let me know whether I can explicitly set focus on more than one object at a time. i.e., user name and password fields"

Thanks and regards,
Mithun

The following code is working fine... except for
.... it is requesting me to set the focus on the text box (Password) field too....
Please could you let me know whether I can explicitly set focus on more than one object at a time.if so how?


Private Sub Login_Click()
On Error GoTo Err_Login_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim user_name As String
Dim password As String
Dim temp As String

Dim rs As ADODB.Recordset
Dim sSQL As String
Combo2.SetFocus
Set rs = New ADODB.Recordset
sSQL = "Select * from user_validate Where user_Name = '" & Combo2.SelText & "'"
rs.Open sSQL, CurrentProject.Connection
' rs.MoveFirst


If rs.EOF Then
MsgBox "User Not Found"
'Prompt again for user name /pwd
Else
'MsgBox "User Found"
'Write Code to Open ur Application
End If
rs.Close
Set rs = Nothing

' commented **** Mithun *****
' Combo2.SetFocus

'sSQL = "SELECT user_validate.user_name FROM user_validate"
'temp = Combo2.SelText
'temp = user_validate.user_name

'If user_validate.user_name = Combo2.SelText And user_validate.password = Text4.Text Then
'sSQL = "Select * From User_validate Where User_Name = '" & Combo2.SelText & "' And Password = '" & Text4.Text & "'"

' stDocName = "dhome"
' DoCmd.OpenForm stDocName, , , stLinkCriteria

' Else
'MsgBox "Invalid user id or password, please try again", vbOKOnly

'End of commented section **** Mithun *****

Exit_Login_Click:
Exit Sub

Err_Login_Click:
MsgBox Err.Description
Resume Exit_Login_Click
' End If

End Sub
Sep 24 '07 #12
hariharanmca
1,977 1GB
Hi Veena,
Thanks a lot for the help and guidance.....
I have a question with regards to setting the focus on an object "
Please could you let me know whether I can explicitly set focus on more than one object at a time. i.e., user name and password fields"
To make set focus

Expand|Select|Wrap|Line Numbers
  1. txtCtrlName.SetFocus
You cannot make set focus for two object at a time
Sep 24 '07 #13
jagu
2
Please could some one provide me the code to validate the user name and password fields using Vb for MS access.

Fields ::
User name :: text box
Password :: text box
Login :: button

The form should accept the user name and password from the text box , validate the same against a table on MS access if successful should allow the user to proceed to next form else display a alert/error message.


Thanks a lot,
Mithun.

Reply from Mr.Jack ( Diploma engineer ) ongoing with AMIE

after dragging controls on active control form


on login button write this following code

a=trim(val(username.text)
b=trim(val(password.text)
while adodc1.recordset.eof<>true
if adodc1.recordset.fields("username")=a then
if adodc1.recordset.fields("password")=b then
login.setfocus
exit sub
else
adodc1.recordset.movenext
end if
else
adodc1.recordset.movenext
end if
wend
msgbox " invalid login",vbinformation
username.text=""
password.text=""
username.setfocus
Sep 24 '07 #14
HI,
Thank you every one for the help and guidance provided. in getting this task completed.

Mentioned below is the final version of the code.

regards,
Mithun

Private Sub Login_Click()
On Error GoTo Err_Login_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim user_name As String
Dim Password As String
Dim temp As String

Dim rs As ADODB.Recordset
Dim rss As ADODB.Recordset

Dim sSQL As String
Dim tSQL As String
Dim x As String

Combo2.SetFocus
Set rs = New ADODB.Recordset
sSQL = "Select password from user_validate Where user_Name = '" & Combo2.SelText & "'"
rs.Open sSQL, CurrentProject.Connection
If rs.EOF Then
MsgBox "Either the user name or password entered are invalid. Please try again. ", vbOKOnly
Else
rs.MoveFirst

While rs.EOF = False
x = rs(0).Value
rs.MoveNext
Wend




Text4.SetFocus

Set rss = New ADODB.Recordset
tSQL = "select * from user_validate where password = ' " & Text4.Text & "'"

rss.Open sSQL, CurrentProject.Connection

If x <> Text4.Text Then
MsgBox "User Not Found"

'Prompt again for user name /pwd
Else
Combo2.SetFocus

MsgBox " " & Combo2.SelText & " Welcome to DESTINATION ONE ", vbOKOnly
DoCmd.Close
stDocName = "dhome"
DoCmd.OpenForm stDocName, , , stLinkCriteria
'Write Code to Open ur Application
End If
End If


rs.Close
Set rs = Nothing


Exit_Login_Click:
Exit Sub

Err_Login_Click:
MsgBox Err.Description
Resume Exit_Login_Click
' End If


End Sub
Sep 26 '07 #15

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

Similar topics

1
by: hkadhim | last post by:
hi all, I am trying to validate a user name and password using server 2000 domain validation. so users would use their normal ID and passwords to login. does anyone know how to do it or have any...
3
by: mo | last post by:
The code I've pasted below is taken directly from Microsoft's site at http://support.microsoft.com/default.aspx?scid=kb;EN-US;308157 As far as I can tell the error is raised on this line: conn...
8
by: DB2-newbie | last post by:
As a newbie to DB2 I have a strange problem on a zSeries linux box I hope someone can answer. I have created a linux user, user=mytest pw=mytest who is the instance owner and has created a...
7
by: Marc Solé | last post by:
Hello all, I have a web application that runs in a server and makes a Windows user validation to loggin. My question is, how can I get that loggin user, password and domanin to use it in my...
4
by: joesin | last post by:
I recently found a vulnerability on my website that allowed sql injection. I have been trying to write some code that would clean user data but have been running into problems. The validation still...
3
by: Dmitry | last post by:
I am trying to figure out how to pass set of credentials to System.IO Challenge is: App is running under one set of credentials, but via GUI user have a chance to enter another set. I would like...
2
by: shapper | last post by:
Hello, I am trying to check if a user is valid as follows: Response.Write(Membership.ValidateUser("usr", "pass").ToString) It always gives me FALSE. The username and password are correct....
8
by: ajos | last post by:
hi frnds, im trying to convert my servlets database configuration from ms access to mysql database.however im getting some error like no driver found exception. to verify this error ive...
2
by: AAaron123 | last post by:
I think I can do this but can't seem to get it to work. Can I add a few lines to my web.config to allow username ABC to login with password QWERTYU$$ and role Administrator? I'm using...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.