Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8103993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:42:34+00:00 2026-06-05T23:42:34+00:00

Each user object in my database has an incremental ID (1, 2, 3, …).

  • 0

Each user object in my database has an incremental ID (1, 2, 3, …). The URL to view a user’s profile contains the ID of the user object; e.g. http://www.example.com/users/1. This way everyone can see how many users there are on the website, how fast the userbase is growing etc. I don’t want to give that information away.

I would like to convert the incremental ID to a fixed length string in Base58 format, so the URL would look like http://www.example.com/users/2WNrx2jq184 Also, I need the reverse function that converts the string back to the original ID. The reverse function should not be easy to reverse engineer.

The best Python code I found for this purpose is https://github.com/JordanReiter/django-id-obfuscator. It is very good, but in some cases it adds a 0 and/or . character, which leads to strings that are not in Base58 and not of fixed length.
(See utils.py lines 24 and 29.)

How can I improve django-id-obfuscator to result in fixed length base58 obfuscated IDs, or how can I create such obfuscated IDs in Python?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:42:35+00:00Added an answer on June 5, 2026 at 11:42 pm

    If you want to properly do this, take your user ID, pad it with leading zeros, then encrypt it with something like AES and encode the result with base58. To get the ID back, just decode, decrypt and int() the result.

    So for encryption:

    >>> from Crypto.Cipher import AES
    >>> import base64
    >>> obj = AES.new('yoursecretkeyABC')
    >>> x = base64.encodestring(obj.encrypt("%016d"%1))
    >>> x
    'tXDxMg1YGb1i0V29yCCBWg==\n'
    

    and decryption

    >>> int(obj.decrypt(base64.decodestring(x)))
    1
    

    If you can live with weak crypto, you could also simply xor the padded ID with a key:

    >>> key = [33, 53, 2, 42]
    >>> id = "%04d" % 1
    >>> x = ''.join([chr(a^ord(b)) for a, b in zip(key, id)])
    >>> x
    '\x11\x052\x1b'
    >>> int(''.join([chr(a^ord(b)) for a, b in zip(key, x)]))
    1
    

    But this is much less secure since you should never use the same OTP for multiple messages. Also make sure the key is the same length as your padded ID.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Each user of my site has their own profile page, which contains several items
I have a User object/mapping in my application. Each user has a list of
I have an application where for each object the user can specify his own
I am passing an object like this: -@users.each do |user| %tr %td=link_to(user.first_name, users_user_path(user), :title
I'm implementing a service where each user must have his own json/document database. Beyond
I am working in a project where each user has a big avatar and
My schema is quite simple- Each user has an id and name. There are
I'm working on web application which has a database UserName|Password|UserType Anil|Anil|Manager ghouse|Ghouse|Admin raghu|raghu|User Now
I have an application which communicates with a database. Each table has a unique
Say I have a collection of Users. Each user has a User_ID , Username

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.