VB6	Secure Functionality With a Hashed Value
Listing 1 You can use the Crypto API to derive hashed data from passwords. You can compare 
this data with hashed versions of passwords stored in a database or other source.


' Obtain the cryptographic context
hcsp = AcquireContext(PROV_RSA_FULL)
If hcsp = 0 Then GoTo ghexit

' Create a hash containing the password
hhash = GetHashedData(hcsp, txtPassword.Text)
If hhash = 0 Then GoTo ghexit

' Retrieve the length of the hash (typically
' 16 or 20 bytes depending on the algorithm
datalengthlength = 4
res = CryptGetHashParamSize(hhash, _
	HP_HASHSIZE, datalength, datalengthlength, 0)

' Load the hash into a string buffer
hashdata = String$(datalength, 0)
res = CryptGetHashParam(hhash, HP_HASHVAL, _
	hashdata, datalength, 0)
If res = 0 Then GoTo ghexit
hashdata = Left$(hashdata, datalength)

' And convert the hash into hex for ease of
' viewing and comparison in this particular example.
HexHashData = StringToHex(hashdata)

Select Case HexHashData
	Case "2AC9CB7DC02B3C0083EB70898E549B63"
		PasswordValid = True
	Case "6F9DFF5AF05096EA9F23CC7BEDD65683"
		PasswordValid = True
End Select

If PasswordValid Then
	Set MainOp = New clsFunctionality
	MainOp.Operation
Else
	MsgBox "Invalid Password"
End If

