UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> Hash    
Image:NotifWarningStrong.gif BUG REPORT: Note that there is a bug with this function where different strings may return the same has value. Click the Talk button for forum discussion on the topic. A complete hash using the SHA-256 algorithm can be found here


Perform a simple one way hash on a passed in string value. This is a good way to obfuscate data. For example, if you wish to store a user name and password. You can store password by passing the value through the hash function first, then storing the hashed value. Then when you want to verify a user, you ask for their pwd and run their input through the hash function to perform the lookup varification of the user name and pwd given.

' Hash
' http://www.utteraccess.com/wiki/Hash
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
' You are free to use this code in any application,
' provided this notice is left unchanged.
' rev  date                          brief descripton
' 1.0  2011-04-15                    
Public Function Hash(ByVal strHashThis As String) As Long

   Dim i As Long, h As Long
   Dim lngTemp As Long

   h = Len(strHashThis)
   For i = 1 To h
       lngTemp = (Asc(Mid$(strHashThis, h - i + 1, 1)) + Asc(Mid$(strHashThis, i, 1))) Xor lngTemp
   Next i

   Rnd -1

   Randomize lngTemp

   Hash = (Rnd() * &H7FFFFFFF) And &HFFFFFFFF

End Function

Creative Commons License
Hash by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 10,558 times.  This page was last modified 13:13, 18 January 2012 by Jack Leach. Contributions by Brent Spaulding  Disclaimers