Set a password for a database in an "exclusive" way

Source: Internet
Author: User
Tags goto access database

As we all know, the security of the database is very important, it directly affects the wide application of the database. Users can use either method to secure a database application or combine several methods. It is easy to take advantage of the encryption and other protection methods provided by the Access database itself, which will not be discussed in this article. In Access database, embedded a strong database operation language--visualbasic language, so you can use VisualBasic programming, to achieve some complex functions.

For some companies, the payroll management of employees is a modest problem. Sometimes, leaders need to know how each employee's income will be paid over a period of time in order to master the bonuses. To this end, the author designed a "Payroll management" database, you can query by time, and according to the selected wage category for statistics. In order to prevent others from viewing this database, the author used the "Exclusive" way to set the database password. This approach also has some limitations, if the user happens to provide the correct database password, the method can not control the user to operate the database.

----to further prevent staff from looking at the statistics of wages (that is, some bonuses are not public, other than the leader should not know the number of wages, the author also created a password table, set the password, remember and hide it (first select the password table, and then click the Window menu, "Hide" command, You can hide this form. Then, in the Worker Pay dialog form, add the Password text box and add the following statement to the preview and Print event procedures:

DoCmd.ApplyFilter , "密码 = Forms!
职工工资对话框!PassText"
If Not IsNull([密码]) Then
/*其他代码*/
Else
MsgBox "请输入正确的密码!"
PassText.SetFocus
End If
/*其他代码*/

In this way, the dual encryption function is realized. Even if the user can access the database, if the second time does not provide the correct password, he will not be able to preview and print a certain time range of statistical results. This further limits the user's unauthorized access.

----to improve the security of your database, you should change your password every once in a while. To do this, in the Worker Pay dialog form, you add a "Change Password" subform, which you can change at any time by adding the following code to the form.

Private Sub确定_Click()
On Error GoTo Err_确定_Click
DoCmd.ApplyFilter , "密码
= Forms!更改密码!Text1"
If IsNull([密码]) Then
MsgBox ("密码不正确,
请再输入一次")
Text1.SetFocus
GoTo Exit_确定_Click:
End If
If Text3.Value < > Text2.Value Then
Text3.SetFocus
MsgBox ("请输入正确的确认密码")
Else:
密码 = Text3.Value
DoCmd.Close
End If
Exit_确定_Click:
Exit Sub
Err_确定_Click:
MsgBox Err.Description
Resume Exit_确定_Click
End Sub

After you change your password, you should remember this password for later use.

Design your program and hide the code in the same way that you hide the table, in case someone else modifies or peeks at it. The method described here is only a small technique for implementing encryption in a program, and it can be used for encryption in other database management.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.