微信公众号 
图码生活

每天发布有五花八门的文章,各种有趣的知识等,期待您的订阅与参与
电脑报 1992-2001 十年文章全集
电脑报 1992-2001 十年文章全集
包含从 1992 年 - 2001 年间,两万余篇期刊文章,查询最少输入两个字符
随便看看
读取中
读取中
标题用VB编写查看MDB文件密码的程序
栏目软件世界
作者杨杰
发布2001年11期
  凡是使用 ACCESS 的人都知道,为了保护自己的数据不被别人偷看,可以给自己的MDB数据库文件设置密码,方法是选取“工具/安全/设置数据库密码” 菜单,然后输入密码;以后每次打开数据库文件时,系统就会首先要求输入密码,只有输入正确才被允许访问数据库。(

)
  但是有些时候会把自己设置的密码遗失或忘记,这时就需要有一种方法来查看 MDB 文件的密码。在这里,我用 VB 编写了一段小程序,该程序代码如下:
  Option Explicit
  Private Sub cmd_Click()
  On Error GoTo PROC
  Dim strbytes(13) 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 Dir(strfile) <> “” Then
  txt(0) = Trim(strfile)
  Open Trim(strfile) For Binary Access _
  Read As #1' 以读取字节流的方式打开件
  Get #1, 67, strbytes '从文件位置“67” 处读取字节流
  Close #1 ' 关闭文件
  strpw = “”
  If ((strbytes(0) Xor 134) = 0) Then
  strpw = “该数据库没有密码”
  Else
  ' 以下这段代码用来还原密码
  ' 即数组中每个字节和一个相应的数值(16进制)做“异或” 运算
  strpw = strpw & Chr$(strbytes(0) Xor &H86)
  strpw = strpw & Chr$(strbytes(1) Xor &HFB)
  strpw = strpw & Chr$(strbytes(2) Xor &HEC)
  strpw = strpw & Chr$(strbytes(3) Xor &H37)
  strpw = strpw & Chr$(strbytes(4) Xor &H5D)
  strpw = strpw & Chr$(strbytes(5) Xor &H44)
  strpw = strpw & Chr$(strbytes(6) Xor &H9C)
  strpw = strpw & Chr$(strbytes(7) Xor &HFA)
  strpw = strpw & Chr$(strbytes(8) Xor &HC6)
  strpw = strpw & Chr$(strbytes(9) Xor &H5E)
  strpw = strpw & Chr$(strbytes(10) Xor &H28)
  strpw = strpw & Chr$(strbytes(11) Xor &HE6)
  strpw = strpw & Chr$(strbytes(12) Xor &H13)
  End If
  txt(1) = strpw ' 输出密码
  End If
  Exit Sub
  PROC
  End Sub
  程序简介:
  该程序包含一个窗体frm_mdbpassword;
  该窗体包含:一个CommandButton控件cmd选择MDB文件并输出密码;
  一个Image控件Image1;
  一个CommonDialog控件cdg显示文件打开选择对话框;
  两个Label控件,lbl(0)和lbl(1);
  两个TextBox控件,txt(0)显示MDB文件路径和文件名称;txt(1)显示该MDB文件的密码。
  注:该程序在中文WIN98中文Visual Basic 6.0中调试通过。