最佳 URL 缩短算法

发布于 2024-10-03 11:17:11 字数 1431 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仅此而已 2024-10-10 11:17:11

随机生成一个id,检查是否已经被使用过?

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

沙与沫 2024-10-10 11:17:11

也许你可以使用 SHA 来散列它

编辑:更好地生成一个随机数并对其进行散列,正如 Jon 指出的那样

May be you can use a SHA to hash it

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

杀手六號 2024-10-10 11:17:11

首先,将身份验证信息(例如用户名和密码)放入 URL 中并不是一个好主意(用户只需通过复制/粘贴链接等即可泄露其密码。 )。

也就是说,如果您想隐藏 URL 添加到缩短服务的顺序,您可以使用 MD5 或 SHA1 等加密哈希函数的输出(这被认为是“不可逆的”,例如,无法从输出推导输入),采用 base-64 编码,并采用八个字符。哈希函数的输入可以是 URL(也可能是当前时间)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文