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 6542297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:12:33+00:00 2026-05-25T11:12:33+00:00

Database resources, that can be accessed from webpage that I’m currently working on, have

  • 0

Database resources, that can be accessed from webpage that I’m currently working on, have unique id number with auto_increment set. So url would have to look like some.web.page.com/resource/id-number.

It would be kinda easy for user to notice that he can simply increase or decrease number at the end to get anything he pleases and while security isn’t big concern in this case, I would really like to prevent that kind of behavior.

I was trying to find some function that would convert the number to random string look-a-like, but I failed (didn’t really know what to put in that field on google.com 😉 ). I also have my own ideas, but I prefer to use method that is already working well somewhere. The function needs to be symmetrical so I can easily generate string, and get number from that string. Any advice?

  • 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-05-25T11:12:33+00:00Added an answer on May 25, 2026 at 11:12 am

    Ray Morgan gives an algorithm and an implementation in PHP. The algorithm has a few nice properties, namely:

    • the algorithm is deterministic, i.e., always produces the same obfuscated string for a given numeric ID value.
    • the obfuscation is fully invertible, i.e., if you know (only) the obfuscated value, you can extract the underlying numeric ID
    • doesn’t yield any recognizable patterns (such as simple increasing sequences of integers)
    • it can detect, whether an obfuscated ID string has been tampered with

    The author itself explains the basic steps as follows

    • Create a random number ($segment1) based on a hash of $id.
    • Create a second random number ($segment2) based on a hash of $segment1.
    • Alter $segment2 by adding or subtracting the value of $id.
    • Make a third hash ($segment3) from $segment1 and the altered $segment2. This hash makes it possible to detect any alteration of the encoded ID.
    • Concatenate the three segments into a string,
    • and voilà – you have your obfuscated ID.

    For those like me not comfortable with PHP, a working Common Lisp port of the algorithm could look like:

    #-(and) (ql:quickload "ironclad")
    #-(and) (ql:quickload "trivial-utf-8")
    
    (defpackage "HASHID"
      (:use "COMMON-LISP" "IRONCLAD" "TRIVIAL-UTF-8")
      (:shadowing-import-from "COMMON-LISP" "NULL"))
    
    (in-package "HASHID")
    
    (defparameter +secret+ "Secret Password")
    
    (defun sha1-hex-digest (string &optional (secret +secret+))
      (let ((digest (make-digest :sha1)))
        (update-digest digest (string-to-utf-8-bytes string))
        (update-digest digest (string-to-utf-8-bytes secret))
        (let* ((result (produce-digest digest))
               (length (length result))
               (char-length (* length 2))
               (buffer (make-array char-length :element-type 'character))
               (digits "0123456789ABCDEF"))
          (loop
             :with wp := 0
             :for byte :across result
             :do (setf (char buffer (prog1 wp (incf wp))) (char digits (ash byte -4)))
                 (setf (char buffer (prog1 wp (incf wp))) (char digits (logand byte 15)))
             :finally (return buffer)))))
    
    
    (defun obfuscate-id (identifier)
      (let* ((segment-1 (subseq (sha1-hex-digest (format nil "~D" identifier)) 0 16))
             (segment-2 (subseq (sha1-hex-digest (concatenate 'string segment-1)) 0 8))
             (decimal (parse-integer segment-2 :radix 16))
             (buried-id (if (< identifier decimal) (- decimal identifier) (+ decimal identifier)))
             (new-segment-2 (format nil "~8,'0X" buried-id))
             (segment-3 (subseq (sha1-hex-digest (concatenate 'string segment-1 new-segment-2)) 0     8)))
        (concatenate 'string segment-1 new-segment-2 segment-3)))
    
    
    (defun deobfuscate-id (string)
      (let* ((segment-1 (subseq string 0 16))
             (segment-2 (subseq string 16 24))
             (segment-3 (subseq string 24))
             (expected-2 (subseq (sha1-hex-digest segment-1) 0 8))
             (expected-3 (subseq (sha1-hex-digest (concatenate 'string segment-1 segment-2)) 0 8)))
        (and (string-equal segment-3 expected-3)
             (let* ((v1 (parse-integer segment-2 :radix 16))
                    (v2 (parse-integer expected-2 :radix 16)))
               (abs (- v1 v2))))))
    

    Note, that the original implementation generated a base-64 encoded string from the obfuscated ID and used that as the actual value. I did omit this step here, but it should be simple to add, in particular, if your programming language of choice comes with base-64 support.

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

Sidebar

Related Questions

A database application that I'm currently working on, stores all sorts of settings in
I am working currently on a web project where users can create image galleries
I have an internal WPF client application that accesses a database. The application is
I have an application that is currently running on IIS 6.0 with one worker
I'm developing a twisted.web server - it consists of some resources that apart from
I have a massive amount of data that needs to be read from mysql,
I have written a very complex database migration script in Groovy, that runs just
I have a database that it is always changing... updates, inserts and deletes. For
I have a web application that I'm working on that has always been in
We are using fmt:setBundle to load a resource bundle from a database (we extended

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.