2023年11月23日发(作者:)

VB编写查看MDB文件密码的程序

杨杰

2001 11

凡是使用 ACCESS 的人都知道,为了保护自己的数据不被别人偷看,可以给自己的MDB

数据库文件设置密码,方法是选取“工具/安全/设置数据库密码” 菜单,然后输入密码;以

后每次打开数据库文件时,系统就会首先要求输入密码,只有输入正确才被允许访问数据库。

^11020504a^

但是有些时候会把自己设置的密码遗失或忘记,这时就需要有一种方法来查看 MDB

文件的密码。在这里,我用 VB 编写了一段小程序,该程序代码如下:

Option Explicit

Private Sub cmd_Click()

On Error GoTo PROC

Dim strbytes13 As Byte '该数组存放从文件中取出的经过加密的密码

Dim strfile As String '该变量存放MDB文件路径以及文件名

Dim strpw As String '该变量存放经还原后的密码

'选择要查看密码的MDB文件

With cdg

.CancelError = True

.Filter =*.mdb*.mdb

.ShowOpen

strfile = .FileName

End With

If Dirstrfile <> “” Then

txt0 = Trimstrfile

Open Trimstrfile For Binary Access _

Read As #1 以读取字节流的方式打开件

Get #1 67 strbytes '从文件位置“67 处读取字节流

Close #1 关闭文件

strpw = “”

If strbytes0 Xor 134 = 0 Then

strpw = “该数据库没有密码”

Else

以下这段代码用来还原密码

即数组中每个字节和一个相应的数值(16进制)做“异或” 运算

strpw = strpw & Chr$strbytes0 Xor &H86

strpw = strpw & Chr$strbytes1 Xor &HFB

strpw = strpw & Chr$strbytes2 Xor &HEC

strpw = strpw & Chr$strbytes3 Xor &H37

strpw = strpw & Chr$strbytes4 Xor &H5D

strpw = strpw & Chr$strbytes5 Xor &H44

strpw = strpw & Chr$strbytes6 Xor &H9C

strpw = strpw & Chr$strbytes7 Xor &HFA

strpw = strpw & Chr$strbytes8 Xor &HC6

strpw = strpw & Chr$strbytes9 Xor &H5E

strpw = strpw & Chr$strbytes10 Xor &H28

strpw = strpw & Chr$strbytes11 Xor &HE6

strpw = strpw & Chr$strbytes12 Xor &H13

End If

txt1 = strpw 输出密码

End If

Exit Sub

PROC

End Sub

程序简介:

该程序包含一个窗体frm_mdbpassword

该窗体包含:一个CommandButton控件cmd选择MDB文件并输出密码;

一个Image控件Image1

一个CommonDialog控件cdg显示文件打开选择对话框;

两个Label控件,lbl0)和lbl1

两个TextBox控件,txt0)显示MDB文件路径和文件名称;txt1)显示该MDB

文件的密码。

注:该程序在中文WIN98中文Visual Basic 6.0中调试通过。