Uniquely identifying a WordPress blog?

I'm working on implementing a WordPress plugin which has a one-click setup procedure that calls my server to set things up by sending a unique key to the server, and then use that code from that time on to configure the system in the future.

Is there a way in WordPress to get a unique blog ID?

At first glance, I looked at get_current_blog_id, but it is a pretty local and non-unique number.

Then, I looked at maybe taking the NONCE_KEY defined in wp-config.php, and hashing that with SHA512. However, I am concerned about the security risk in this (even though I know that an SHA512 is hard to bruteforce).

Is this concern that I have regarding security reasonable? Is there any other way I can identify a WordPress blog uniquely?

Upvotes: 0

Views: 78

Answers (1)

Xairoo
Xairoo

Reputation: 345

You could create a function to create an unique blog ID, but based on what? URL could change, name could change, theme, server ip and so on. There isn't really an unique and static variable.

Create your own one!

I use serials and tokens for this. The blog submits a serial to receive a token from my api. You could create the serial on the first request, so the blog owner doesn't have to enter it. Now send the serial and a generated token back to the blog and store this data in the database: update_option('name', 'token') or just add_option('name', 'token'). There is your unique id!

  • on every new blog "registration" (blog has still no serial) generate a unique serial and a token
  • store the serial and the token on your database to verify the blog again
  • the token should change from time to time
  • you could also check against older tokens (let say the last 2 tokens...) to be more flexible

Upvotes: 2

Related Questions