Tuesday, March 27, 2012

Database catalog unique identifier

I need to develop a strong licensing solution based on the database accessed...

Currently our solution is easily hackable because the the license information is kept in the database of your choice and is not dependant on some static information, the current encryption key is static and kept in the software so it can be hacked easily. What i want to do to change this is simple in nature but i don't know how to get that one particular info i need.

I want to get some kind of unique identifier for a database (catalog) that sql server could generate. This info must be static and must not be movable. If for example, someone would backup and restore, this information would not be transfered with the backup. Thus, a user that backups his database and restores it on another database server or another database catalog even on the same server would corrupt his license since the Unique ID returned by the SQL Server would be different; the hashing code would change and thus the decryption would fail.

Is there any such info i can query using SQL that will not require admin rights?

after searching a bit more in the help i found out there was something i could use in sys.databases.

I was thinking of using a combination of the database name, the id column and the creation date to create the key but then it struck me, if someone wants to cancel his licensed solution, i can do wathever process i want, he can just restore it and the license is back online. Thus, for the original question, i'm pretty much done and everything is ok, but now i need to know if there is somewhere in the sys.* that i can find the last restore date so i can prevent database restore from happening...

|||

after even thourough searching even after work hours, i finally found it (8 hours on the subject is enough i think).

Here is the code that will do what i am searching for

SELECT
d.database_id,
d.name,
d.create_date,
r.restore_date
FROM sys.databases AS d
LEFT JOIN sys.database_files AS df ON df.name = d.name
LEFT JOIN RestoreHistory AS r ON r.destination_database_name = d.name
WHERE
d.name = '[DatabaseName]'

I hope this will benefit someone else and not just me

No comments:

Post a Comment