开发者

Best URL Shortening Algorithm [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 7 years ago.

Improve this question

I was wondering what is the best algorithm for URL shortening. I noticed most people do the following:

1) Get Unique auto generated id from database. 2) Encode unique auto generated id to Base 64 value.开发者_运维百科

Its kind of obvious to a user what previous url's might be. What can I do to make it harder for the user to figure out what algorithm I'm using?

Thank you, Tesh


Generate an id at random and check to see if it has been used already?


May be you can use a SHA to hash it

EDIT: Better generate a random number and hash it as Jon pointed out


First of all, it's not a good idea to put authentication information (e.g. usernames and passwords) in URLs (users would reveal their passwords simply by copy/pasting links, etc.).

That said, if you want to obscure the order that URLs were added to the shortening service, you could use the output of a cryptographic hash function such as MD5 or SHA1 (which is considered "irreversible", i.e. infeasible to derive the input from the output), base-64 encode that, and take eight characters, for example. The input to the hash function could be the URL (possibly the current time as well).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜