I need to build a hash based on FirstName/LastName combo. In the database both are 100 chars each max and the hash needs to be 20 chars max.
Is there a way to reliably generate a unique value based on that? Assume that FirstName/LastName combo is unique.
It sounds like you want a unique identifier for each record in the table and that this identifier is not easy to guess. There are multiple ways to achieve this, including:
1. Add a column for the identifier with a
uniqueconstraint and generate a random identifier when you insert the column. If the insertion fails due the identifier already being present, generate a new identifier and try again.2. Add a
auto GUIDcolumn to the table to let the database generate a unique identifier.3. Add a
auto-increment intcolumn to the table to let the database generate a unique identifier and obfuscate that. You can do this, for example, by padding the integer to 16 and encrypting it with a 128-bit block cipher. Example:Note that none of these ways make it impossible to guess the identifier, just more difficult than incrementing an integer by 1. You still need to check if the user is authorised to view the information associated with the identifier.