Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatic Password Retrieval

Status
Not open for further replies.

NJLDoc

Programmer
Jan 25, 2002
93
In VB 6 I was able to retrieve through code a password from MS Access 97 or 2000. I have a front end application that connects to several databases each with a password. From time to time I change the password. The code I have in VB 6 is as follows:
Public Function StPasswordOfStDatabase(ByVal dbFullPath As String) As String
Dim hFile As Integer
Dim ich As Integer
Dim stBuffer As String
Dim rgbytRaw() As Byte
Dim rgbytPassword() As Byte
Dim rgbytNoPassword() As Byte

' Create the byte array with the 20 bytes that are present when there
' is no database password
'Keyword 'ChrB' not supported in Visual Basic .NET
rgbytNoPassword = ChrB(134) & ChrB(251) & ChrB(236) & ChrB(55) & ChrB(93) & _
ChrB(68) & ChrB(156) & ChrB(250) & ChrB(198) & ChrB(94) & _
ChrB(40) & ChrB(230) & ChrB(19) & ChrB(182) & ChrB(138) & _
ChrB(96) & ChrB(84) & ChrB(148) & ChrB(123) & ChrB(54)

' Grab the 20 bytes from the real file whose password
' we are supposed to retrieve
hFile = FreeFile
Open dbFullPath For Binary As #hFile
Seek #hFile, 66 + 1
rgbytRaw = InputB(20, #hFile)
Close #hFile

' Enough prep, lets get the password now.
ReDim rgbytPassword(0 To 19)
For ich = 0 To 19
rgbytPassword(ich) = rgbytRaw(ich) Xor rgbytNoPassword(ich)
Next ich

' Add a trailing Null so one will always be found, even if the password is 20
' characters. Then grab up to the first null we find and return the password
stBuffer = StrConv(rgbytPassword, vbUnicode) & vbNullChar
StPasswordOfStDatabase = Left$(stBuffer, InStr(1, stBuffer, vbNullChar, vbBinaryCompare) - 1)

End Function
 
What's your question?

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
The ChrB does not work in .net and so the above VB6 code does not retrieve the password. What is the correction to allow password retrieval in VB .Net?

I can't believe I forgot the question. Thanks.
 
Sounds like what you need to do is use an array of Bytes.
Code:
Private NoPaswd As Integer() = { 134, 251, 236, 55, 93,
68, 156, 250, 198, 94, 40, 230, 19, 182, 138, 96,
84, 148, 123, 54 }
You'd then read your file as bytes like you're doing, and compare the two byte arrays like you're doing.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
This I think gets me a step closer. However as I am fairly new to .net I am still troubled by the conversion from VB6 to .net.

InputB has no equivalent and the conversion to unicode is not recognized:
rgbytRaw = InputB(20, #hFile)
stBuffer = StrConv(rgbytPassword, vbUnicode) & vbNullChar

I appreciate your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top