Secure programming of Access database

Almost everyone who uses a Microsoft Access application uses one of the (or all) of the following ways to protect the database (database), to lock their hands and lock the curious employees:

Almost everyone who uses a Microsoft Access application uses one of the (or all) of the following ways to protect the database (database), to lock their hands and lock the curious employees:

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

2. Use the Make MDE file function to prevent modification of code, form design and report design. In this way, the structure and data of tables can still be taken to transfer to another .MDB file that is viewed and modified.

3. Use Encrypt / Decrypt database . to encrypt the database, prevent utility programs from processing decrypted documents, but still use Access to open.

4. Use the Set database password function to specify the password for the database. This is a little annoying if there is a table in another database that links (links) to it. If I forgot my password . would I cry?

5. Design a boot form, which requires a name and password, using the Startup dialog box (from the Display Form / Page list ) to specify this form to be opened each time you first open the database. This way, you can hide the Database window, where you can view and select the components of the database to repair.

In the above ways, the 5th way can still be overcome by pressing and holding the Shift key while opening the database. To fix this, we can use Visual Basic to assign False to the AllowBypassKey property to disable the Shift key when opening the database.

Suppose you have a database named dbLock.MDB. Every time people open it, you want the frmKhoiDong form to always be displayed first by specifying Display Form / Page as frmKhoiDong . To change the AllowBypassKey property , it is required to open the database, assign a new value to this attribute, close the database, then open the new database. Remember, it is necessary to lock it so that people cannot open it and open it, which means we must have the key to open it. The key here is another form, such as frmChiaKhoa .

Once you have changed the AllowBypassKey property , make sure the frmKhoiDong form is displayed when you open the database. So we put the key through this form by drawing a control box (as long as it has a procedure to handle the Click situation is okay), such as label lblChiaKhoa , then set the Visible property to No and add command line DoCmd.OpenForm 'frmChiaKhoa' into the procedure to handle the situation Click . You have to remember the location of the label to get the key out. Thus, the remaining problem is in the frmChiaKoa form.

Open the Microsoft Visual Basic editor window, select References . to ensure Microsoft DAO xx.xx Object Library (where xx.xx version may be: 2.5 or 3.51 or 3.6 depending on Access version, of course should choose the latest version) selected in the Available References list.

Picture 1 of Secure programming of Access database

Figure 1 : Design form

Figure 1 is a frmivided form. The tree needs to be designed, including a text box txtPassword to receive the password that the person who needs to unlock must type, a cmdLock button performs the database lock and a cmdUnlock button to perform database unlock . Done, you type the procedures to process as code 1. Before messing up this on a database, you should copy the database to prevent the lock problem but cannot open it (because you mistakenly type the command line) .

Code snippet 1

'The ChangeProperty function changes the properties of the database

Function ChangeProperty (strPropName, varPropType, varPropValue)

Dim dbs As Database, prp As Property

Const conPropNotFoundError = 3270

Set dbs = CurrentDb

On Error GoTo Change_XuLyLoi

dbs.Properties (strPropName) = varPropValue

ChangeProperty = True

Change_KetThuc:

Exit Function

Change_Language:

'Attribute not found

If Err = conPropNotFoundError Then

Set prp = dbs.CreateProperty (strPropName, _

varPropType, varPropValue)

dbs.Properties.Append prp

Next Resume

Else

'I don't know what the error is

ChangeProperty = False

Resume Change_KetThuc

End If

End Function

'Handling the situation of selecting the [Lock database] button

Private Sub cmdLock_Click ()

'This form is preloaded

ChangeProperty "StartupForm", dbText, "frmKhoiDong"

ChangeProperty "StartupShowDBWindow", dbBoolean, False

ChangeProperty "StartupShowStatusBar", dbBoolean, False

ChangeProperty "AllowBuiltinToolbars", dbBoolean, False

ChangeProperty "AllowFullMenus", dbBoolean, False

ChangeProperty "AllowBreakIntoCode", dbBoolean, False

ChangeProperty "AllowSpecialKeys", dbBoolean, False

 

'Do not use the Shift key to skip the form frmKhoiDong

ChangeProperty "AllowBypassKey", dbBoolean, False

 

MsgBox "Database has been locked! Close the database, _

then reopen it to press-es. ", vbOKOnly," eChip Security "

cmdExit.SetFocus

cmdUnlock.Visible = True

cmdLock.Visible = False

End Sub

'Handling the situation to select the button [Open database]

Private Sub cmdUnlock_Click ()

'No boot form needed

ChangeProperty "StartupForm", dbText, ""

ChangeProperty "StartupShowDBWindow", dbBoolean, True

ChangeProperty "StartupShowStatusBar", dbBoolean, True

ChangeProperty "AllowBuiltinToolbars", dbBoolean, True

ChangeProperty "AllowFullMenus", dbBoolean, True

ChangeProperty "AllowBreakIntoCode", dbBoolean, True

ChangeProperty "AllowSpecialKeys", dbBoolean, True

ChangeProperty "AllowBypassKey", dbBoolean, True

MsgBox "The database has been unlocked! _

Close the database, then reopen it with press-approval. ", _

vbOKOnly, "eChip Security"

cmdExit.SetFocus

txtPassword = ""

cmdLock.Visible = True

cmdUnlock.Visible = False

txtPassword.Visible = False

End Sub

'Handle the situation when opening the form

Private Sub Form_Open (Cancel As Integer)

Dim dbs As Database

Set dbs = CurrentDb

On Error GoTo KhongCoThuocTinh_Err

If dbs.Properties ("AllowBypassKey") Then

cmdLock.Visible = True

txtPassword.Visible = False

Else

cmdLock.Visible = False

txtPassword.Visible = True

End If

Sub Exit

KhongCoThuocTinh_Err:

cmdLock.Visible = True

txtPassword.Visible = False

End Sub

'When people type the password and press the Enter key

Private Sub txtPassword_LostFocus ()

If txtPassword = "echip" Then

cmdUnlock.Visible = True

End If

End Sub

Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile