Access Database Security Programmer

Access Database Security Programmer

Almost anyone who uses a Microsoft Access application also uses one of the following (or all) methods to protect the database: locking, locking,

1. Protect the VBA code (Visual Basic for Application) by selecting the Properties on the menu Tools of the editor window Microsoft Visual Basic then select the page Protection on the dialog box Project Properties . Finally, select Lock project for viewing , followed by password protection. In this way, the structure and data of the tables can be viewed and modified.

2. Use the function Make MDE file to prevent code modifications, form design and report design. In this way, the structure and data of the tables can still be retrieved for transfer to another .MDB file that views and modifies.

3. Use the function Encrypt / Decrypt database ... to encrypt the database, prevent utilities or decode documents, but still use Access to open it.

4. Use the function Set database password to set the password for the database. This is a bit of a hassle if there is a table in another database that links to it. If you forgot your password ... then cry!

5. Design a startup form, which requires the given name and password, using the dialog box Startup (from the list Display Form / Page ) to open this form the first time you open the database. Thanks to this, we can hide the window Database , where you can view and select the components of the database for repair.

In the above ways, the fifth way can still be overcome by pressing and holding the key Shift while opening the database. To fix this, you can use Visual Basic to assign values False for attributes AllowBypassKey to disable the key Shift when opening the database.

Suppose you have a database named dbLock.MDB. Each time you open it, you want the form frmKhoiDong Always displayed first Display Form / Page was frmKhoiDong . To change a property AllowBypassKey , forced to open the database, set new values ​​for this property, close the database, the next time open the new squeeze. Remember, the key should not be opened people can open themselves, that is, we must have the key to open. Here is another form, such as frmChiaKhoa

Once the attribute has been changed AllowBypassKey Okay, sure the form frmKhoiDong is displayed when opening the database. So we put the key through this form by drawing a widget (as long as it has a procedure for handling the situation Click is okay), such as label lblChiaKhaa , then set the attribute Visible was and add the command line DoCmd.OpenForm "frmChiaKhoa" in case handling procedures Click . You must remember the label position lblChiaKhaa to pull out the key. Thus, the remaining problem lies in the form frmChiaKhoa

You open the Microsoft Visual Basic editor window, select the item References ... to insure Microsoft DAO xx.xx Object Library (in which, version xx.xx maybe: or 3.51 or Depending on the version of Access, of course, select the latest version) was selected in the list Available References

Figure 1 : Forms need to be designed

Figure 1 is a form frmChiaKhoa should be designed, including a text box txtPassword To receive a password that people need to unlock, type a button cmdLock Performs a database lock and a command button cmdUnlock performs database unlocking. Finished, you type the processing procedures as code 1. Before you panic on a database, you should copy the database protection to avoid locking problems but not open (because you mistype the command line) .

Listing 1

'Jaw ChangeProperty change the properties of the database

Function ChangeProperty (strPropName, varPropType, varPropValue)

& nbsp; Dim dbs As Database, prp As Property

& nbsp; Const conPropNotFoundError = 3270

& nbsp; Set dbs = CurrentDb

& nbsp; On Error GoTo Change_XuLyLoi

& nbsp; dbs.Properties (strPropName) = varPropValue

& nbsp; ChangeProperty = True

Change_KetThuc:

& nbsp; Exit Function

Change_XuLyLoi:

& nbsp; 'Attribute not visible

& nbsp; If Err = conPropNotFoundError Then & nbsp;

& nbsp; Set prp = dbs.CreateProperty (strPropName, _

& nbsp; varPropType, varPropValue)

& nbsp; dbs.Properties.Append prp

& nbsp; Resume Next

& nbsp; Else

& nbsp; 'I do not know what's wrong

& nbsp; ChangeProperty = False

& nbsp; Resume Change_KetThuc

& nbsp; End If

End Function

'Handle situations by selecting buttons [Database lock]

Private Sub cmdLock_Click ()

& nbsp; 'This form is preloaded

& nbsp; ChangeProperty "StartupForm", dbText, "frmKhoiDong"

& nbsp; ChangeProperty "StartupShowDBWindow", dbBoolean, False

& nbsp; ChangeProperty "StartupShowStatusBar", dbBoolean, False

& nbsp; ChangeProperty "AllowBuiltinToolbars", dbBoolean, False

& nbsp; ChangeField "AllowFullMenus", dbBoolean, False

& nbsp; ChangeProperty "AllowBreakIntoCode", dbBoolean, False

& nbsp; ChangeProperty "AllowSpecialKeys", dbBoolean, False

& nbsp;

& nbsp; 'Do not use the Shift key to skip the form frmKhoiDong

& nbsp; ChangeProperty "AllowBypassKey", dbBoolean, False

& nbsp;

& nbsp; MsgBox "The database has been locked! Close the database,

& nbsp; and then re-open the squeeze. ", vbOKOnly," eChip Security "

& nbsp; cmdExit.SetFocus

& nbsp; cmdUnlock.Visible = True

& nbsp; cmdLock.Visible = False

End Sub

'Handle situations by selecting buttons [Open database]

Private Sub cmdUnlock_Click ()

& nbsp; 'No more boot styles

& nbsp; ChangeProperty "StartupForm", dbText, ""

& nbsp; ChangeProperty "StartupShowDBWindow", dbBoolean, True

& nbsp; ChangeProperty "StartupShowStatusBar", dbBoolean, True

& nbsp; ChangeProperty "AllowBuiltinToolbars", dbBoolean, True

& nbsp; ChangeProperty "AllowFullMenus", dbBoolean, True

& nbsp; ChangeProperty "AllowBreakIntoCode", dbBoolean, True

& nbsp; ChangeProperty "AllowSpecialKeys", dbBoolean, True

& nbsp; ChangeProperty "AllowBypassKey", dbBoolean, True

& nbsp; MsgBox "The database has been unlocked!

& nbsp; Close the database and then reopen it. ",

& nbsp; vbOKOnly, "eChip Security"

& nbsp; cmdExit.SetFocus

& nbsp; txtPassword = ""

& nbsp; cmdLock.Visible = True

& nbsp; cmdUnlock.Visible = False

& nbsp; txtPassword.Visible = False

End Sub

'Dealing with situations when opening a form

Private Sub Form_Open (Cancel As Integer)

& nbsp; Dim dbs As Database

& nbsp; Set dbs = CurrentDb

& nbsp; On Error GoTo KhongCoThuocTinh_Err

& nbsp; If dbs.Properties ("AllowBypassKey") Then

& nbsp; & nbsp; & nbsp; cmdLock.Visible = True

& nbsp; & nbsp; & nbsp; txtPassword.Visible = False

& nbsp; Else

& nbsp; & nbsp; & nbsp; cmdLock.Visible = False

& nbsp; & nbsp; & nbsp; txtPassword.Visible = True

& nbsp; End If

& nbsp; Exit Sub

& nbsp; KhongCoThuocTinh_Err:

& nbsp; cmdLock.Visible = True

& nbsp; txtPassword.Visible = False

End Sub

'When people type the password and press the key Enter

Private Sub txtPassword_LostFocus ()

& nbsp; If txtPassword = "echip" Then

& nbsp; & nbsp; & nbsp; cmdUnlock.Visible = True

& nbsp; End If

End Sub