Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.6 KiB

  1. Attribute VB_Name = "crypto"
  2. '//+----------------------------------------------------------------------------
  3. '//
  4. '// File: crypto.bas
  5. '//
  6. '// Module: pbadmin.exe
  7. '//
  8. '// Synopsis: Functions to encrypt a database so as to hide passwords
  9. '//
  10. '// Copyright (c) 1997-1999 Microsoft Corporation
  11. '//
  12. '// Author: 11-Jul-2000 SumitC Created
  13. '//
  14. '//+----------------------------------------------------------------------------
  15. Option Explicit
  16. '//+----------------------------------------------------------------------------
  17. '//
  18. '// Function: DBPassword, generates a password
  19. '//
  20. '//+----------------------------------------------------------------------------
  21. Public Function DBPassword() As String
  22. Dim pw As String
  23. Dim i As Integer
  24. On Error GoTo Err:
  25. pw = "PhoneBookAdmin"
  26. pw = Mid(pw, 1, 9) + Chr(Asc(Mid(pw, 10, 1)) + 2) + Mid(pw, 11)
  27. pw = Mid(pw, 5) + Left(pw, 4)
  28. For i = 4 To 12 Step 2
  29. pw = Mid(pw, 1, i - 1) + Chr(Asc(Mid(pw, i, 1)) + 1) + Mid(pw, i + 1)
  30. Next i
  31. DBPassword = ";pwd=" + pw
  32. Err:
  33. ' If Err <> 0 Then MsgBox "manip failed with " & Err.Description
  34. End Function
  35. '//+----------------------------------------------------------------------------
  36. '//
  37. '// Function: ConvertDatabaseIfNeeded, compacts/encrypts db if not already done
  38. '//
  39. '//+----------------------------------------------------------------------------
  40. Public Sub ConvertDatabaseIfNeeded(Workspace As Object, szDBName As String, Options As Variant, fReadOnly As Variant)
  41. Dim db As Database
  42. On Error Resume Next
  43. ' first try to open the db without using a password
  44. Set db = Workspace.OpenDatabase(szDBName, Options, fReadOnly)
  45. If Err.Number = 0 Then
  46. ' db opened without a password. Needs to be converted
  47. db.Close
  48. On Error GoTo CompactErr
  49. DBEngine.CompactDatabase szDBName, "TempConversionDatabase.mdb", dbLangGeneral, dbEncrypt, DBPassword
  50. ' rename the new db (play it safe, make sure the renames succeed first)
  51. Name szDBName As "DeleteThis.mdb"
  52. Name "TempConversionDatabase.mdb" As szDBName
  53. Kill "DeleteThis.mdb"
  54. End If
  55. On Error GoTo CompactErr
  56. ' check that the db will open using the password
  57. Set db = Workspace.OpenDatabase(szDBName, Options, fReadOnly, DBPassword)
  58. db.Close
  59. CompactErr:
  60. 'If Err <> 0 Then MsgBox "Failed to convert db with error: " & Err.Description
  61. Exit Sub
  62. OpenErr:
  63. 'If Err <> 0 Then MsgBox "Failed to open db with error: " & Err.Description
  64. Exit Sub
  65. End Sub