[Django]-Python create a unique hash/encrypted url

2πŸ‘

I am assuming your main idea is to use a unique string as an identifier and you are trying to use hashes as the unique strings.

If so, I would suggest using the uuid module.

Do something like

import uuid
unique_key = str(uuid.uuid4()).replace('-')
url = 'http://127.0.0.1:8080/hiring/application_form/{0}/'.format(unique_key)
# Store the unique_key in the DB with the user object,
# and use it in the email..etc.,

In the URL get map capture the UUID

url(r'^hiring/application_form/(?P<uuid>[a-f0-9]+)/$', applicant_form_view, name='application_form_view')

Then use it in the view and process as you wish.

πŸ‘€Arunmozhi

1πŸ‘

If I was in your shoes (depends on what you wrote here), I’d think about some different strategy.
Instead of just hashing the URL, I’d implement some kind of Map (on the server side) which will store entries of accountId/guestId/hashed URL (or any other unique identifier) to the time when the matching URL has created – then I’d configure a basic throughput which will define for how long each entry is available (you can extend this mechanism as much as you want, it’s very straightforward).

** For the hashed URL you can use some implementation of SHA256 or any other and then encode it using base62 (base64 contains β€œ/” and β€œ?” if I’m not wrong).

Let me know what do you think πŸ™‚

πŸ‘€Dor Farber

Leave a comment