Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Where to store passphrace
Message
 
To
31/07/2008 14:18:29
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows XP
Database:
MySQL
Miscellaneous
Thread ID:
01335597
Message ID:
01335739
Views:
19
Hi Christian,

never store passwords, only hashes. Generating a hash in VFP is relatively easy:
*========================================================================================
* Returns the hash value of a string.
*========================================================================================
LParameter tcString

	#include wincrypt.h

	Local loCrypt, lcHash

	* Special version of _CryptAPI that doesn't hide all methodss
	loCrypt = NewObject("_CryptApi","_CryptX.vcx")
	
	Local lnHashHandle, lnRet, lnLength, lcHash
	lnHashHandle = 0
	lcHash = NULL
	loCrypt.CryptCreateHash( loCrypt.hProviderHandle, dnCALG_SHA, 0, 0, @lnHashHandle )
	
	If loCrypt.nlastapierror = 0
		loCrypt.CryptHashData( m.lnHashHandle, m.tcString, Len(m.tcString), 0 )
		If loCrypt.nlastapierror = 0
			Declare Long CryptGetHashParam in Win32API ;
  			Long hHash, ;
  			Long dwParam, ;
  			Long @pbData, ;
  			Long @pdwDataLen, ;
 				Long dwFlags
 			lnLength = 0
			lnRet = CryptGetHashParam(m.lnHashHandle, dnHP_HASHSIZE, @lnLength, 4, 0)
			If m.lnRet # 0
				Declare Long CryptGetHashParam in Win32API ;
	  			Long hHash, ;
	  			Long dwParam, ;
	  			String @pbData, ;
	  			Long @pdwDataLen, ;
	 				Long dwFlags
	 			lcHash = replicate( Chr(0), m.lnLength )
	 			lnRet = CryptGetHashParam(m.lnHashHandle, dnHP_HASHVAL, @lcHash, m.lnLength, 0)
	 			If m.lnRet == 0
	 				lcHash = NULL
	 			EndIf
			EndIf 
		EndIf 
		loCrypt.CryptDestroyHash( m.lnHashHandle )
	EndIf 


Return m.lcHash
This code assumes that you have a modified version of the _CryptApi.vcx library which has all hidden members set to public. On Vista you can avoid the VCX altogether. Let me know if you also need a Vista-only code sample.
--
Christof
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform