davidguerreiro / evscalculator

Web application for professional pokemon players
https://evscalculator.com
0 stars 0 forks source link

Make unique URL a simple base64 encode #16

Closed jaicab closed 8 years ago

jaicab commented 8 years ago

To speed up, avoid unnecessary stuff on the DB and more importantly, avoid collision, we should create the unique URL from the data we have for each training. So we won't need the id_url field any longer as we can decode it back into the unique row's ID. We should also add some unique strings at the beginning and the end to make it more random.

For example, users with ID '1' and '456' would have this URL strings:

base64encode('calcu1evs'); // Y2FsY3UxZXZz
base64encode('calcu456evs'); // Y2FsY3U0NTZldnM=

The best thing about this is that we than can decode this URL to get the ID:

base64decode('Y2FsY3UxZXZz'); // calcu1evs
base64decode('Y2FsY3U0NTZldnM='); // calcu456evs

We can then make a regular expression to grab the number between 'calcu' and 'evs'. And we got the ID!
:+1:

davidguerreiro commented 8 years ago

Nice idea, completely agree

jaicab commented 8 years ago

This is now done with the Hashids library.