| | |
code for login and password..using vb6
![]() |
•
•
Join Date: Mar 2005
Posts: 71
Reputation:
Solved Threads: 3
•
•
•
•
Originally Posted by sweety***
Hi,
Front end Vb6, back end.. access... connection.. ODADB... can someone please help me with the code for login and password.
just to give some inputs:
in your form you need to have 2 txt field:
1. txtlogin
2: txtpwd
then:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub txtpwd_KeyPress(KeyAscii As Integer) If KeyAscii = vbEnter Then If Len(Trim(txtlogin)) > 0 And Len(Trim(txtpwd)) > 0 Then If CheckPwd(txtlogin, txtpwd) = "ok" Then MsgBox "Password ok" Else MsgBox "Wrong password or Login not found." End If Else MsgBox "Login and password should not be blank" End If End If End Sub Private Function CheckPwd(cLogin As String, cPwd As String) 'in my case i will use dao. you probably using ado just convert it Dim rs As Recordset, ret As String Set rs = opendatabase("c:\temp\login.mdb").openrecordset("select * from tbllogin where ucase(trim(logname)) = '" & UCase(Trim(cLogin)) & "'") If rs.RecordCount <> 0 Then If UCase(Trim(rs("pword"))) = UCase(Trim(cPwd)) Then ret = "ok" Else ret = "wrong" End If Else ret = "wrong" End If rs.Close: CheckPwd = ret End Function
Newvbguy
•
•
Join Date: Nov 2006
Posts: 1
Reputation:
Solved Threads: 0
Just wanted to thank you for the code - This was incredibly helpful.
I set up a similar situation and thought I'd share my code.
Differences:
The table accessed (AdminUser) contains a primary key called 'UserID' [text] and a 'Password' field.
My txtBoxes are named txtUser, and txtPassword
Lots of comments - hope it helps anyone.
I set up a similar situation and thought I'd share my code.
Differences:
- I have not included a keyPress Sub but did it from a button click instead.
- I call from the current database instead of a different one.
- The recordset is exited as soon as possible, and then any conditions not concerning the recordset are administered.
The table accessed (AdminUser) contains a primary key called 'UserID' [text] and a 'Password' field.
My txtBoxes are named txtUser, and txtPassword
Lots of comments - hope it helps anyone.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub cmdMaintenanceSwitchboard_Click() 'check for null password If IsNull(Trim(txtUser)) Then MsgBox "User Name required.", vbExclamation txtUser.SetFocus Exit Sub End If 'check for null password If IsNull(Trim(txtPassword)) Then MsgBox "Password required.", vbExclamation txtPassword.SetFocus Exit Sub End If 'To use the following code, open the code window for a form. 'Under the Tools/References menu, enable the "Microsoft DAO 3.6 Object Library" 'and some may have to disable the "Microsoft ActiveX Data Objects Library" 'declare variables (tempRecordSet becomes an object variable) Dim tempRecordSet As Recordset, Password As String 'open the AdminUsers table '(recordset object variables allow access to records and fields in tables and queries. 'This modified version opens a recordset via a SQL statement to pull the record (if any) where the field matches the txtUser field in the form. 'Since the field is a primary key, there should only be one record if any matches are found. Set tempRecordSet = CurrentDb.OpenRecordset("select * from AdminUsers where UCase(trim(UserID)) = '" & UCase(Trim(txtUser)) & "'") 'retrieve the Password field from the AdminUsers table if the UserID matches the txtUser Field If tempRecordSet.RecordCount <> 0 Then Password = UCase(Trim(tempRecordSet("Password"))) End If 'close the recordset and release the recordset object variable tempRecordSet.Close Set tempRecordSet = Nothing 'check the password If Password <> UCase(Trim(txtPassword)) Then MsgBox "Incorrect password", vbExclamation Else 'passwords match, allow the user to the maintenance switchboard MsgBox "Congratulations! Right Password!!!", vbExclamation End If txtPassword = Empty End Sub
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: How to write a program to register a chart object in excel?
- Next Thread: Can someone help me?
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





