PDA

View Full Version : Login Form



hollyoak05
03-16-2009, 09:43 AM
I have created a login form and need it to open up and prompt for password at the start and then when login directs to my swutchboard. the code i have is as followdOption Compare Database
Private intLogonAttempts As Integer
Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
Me.cboEmployee.SetFocus
End Sub
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check value of password in tblEmployees to see if this matches value chosen in combo box
If Me.txtPassword.Value = DLookup("Password", "tblEmployeePassword", "[EmployeeID]=" & Me.cboEmployee.Value) Then
EmployeeID = Me.cboEmployee.Value
'Close logon form and open splash screen

DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.OpenForm "Switchboard"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub

CreganTur
03-16-2009, 09:51 AM
Welcome to the forum- it's always good to see new members.

From your database screen, click Tools-> Startup, then select your login form as the start form.

You can also change other options, such as what toolsbars/windows users can see.

HTH:thumb

Movian
03-16-2009, 09:58 AM
just as a side note, can i suggest you implement some kind of encryption on the passwords stored in the table? the reason behind this is. If i come along i could for example open a new database. select to import data from your database. Import the passwords table and then have a complete list of passwords. However if you where using say SHA256 (for example). I would only have the encrypted info. This would make the log in setup a little more secure. If you want it i think i have a SHA256 encryption class about here somewhere if you would like it.

Hope this helps as well (although its not DIRECTLY related to your question) :)

Imdabaum
12-21-2009, 04:01 PM
How do you do encyption for a Access table? Plugins? I've never had to build a database from the ground up and most that I maintained were simply using the ULS built into 2003. Now that 2007 doesn't allow for that tool. I have been telling people I don't know how to make their database secure. Anyone have any pointers or how to articles. I'd love to learn.

Movian
12-21-2009, 06:32 PM
there are some encryption and hashing tools included in the access development kit i am working on. Follow the second link in my Signature, its download-able and although i haven't been able to put as much time into it recently as i would like it also includes a number of other tools i hope you may find useful.

Imdabaum
12-22-2009, 10:18 AM
Thanks, I'll check it out.

Imdabaum
12-22-2009, 10:32 AM
Checked it out. That's pretty amazing. Thanks for sharing that.

geekgirlau
12-22-2009, 06:13 PM
Another option: use an API to detect the user's network login name, and compare against a list of valid user names. This way a login form is not required at all (may still want to encrypt the names tho').

Private Declare Function apiGetUserName _
Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Public Function fGetUserName() As String
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~
' Purpose: Capture the network logon name
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~
Dim lngLen As Long
Dim lngX As Long
Dim strUserName As String

On Error GoTo ErrHandler

strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fGetUserName = Left(strUserName, lngLen - 1)
Else
fGetUserName = ""
End If

ExitHere:
Exit Function
ErrHandler:
MsgBox "(bas_General|fGetUserName: " & Err.Number & ")" & vbCrLf & _
Err.Description, vbCritical, "Unexpected Error"
Resume ExitHere
End Function

OBP
12-23-2009, 05:10 AM
Movian, another great option to add to you adddepot :thumb

Nice code geekgirlau. :beerchug:

If I don't speak to you guys again before Christmas I wish you a happy one if you celebrate it.

Movian
12-23-2009, 05:55 AM
Indeed, i may look into incorporating that into the SDK, However if the only check is the user name against a list maybe you would want to hash the user names in the list and compare the hash of the user name you get from this function against the hash stored in the table. Again this way they wont be able to obtain a list of authorized accounts. Meaning they won't instantly know who's account to try and break into