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).
发布评论
评论(3)
随机生成一个id,检查是否已经被使用过?
Generate an id at random and check to see if it has been used already?
也许你可以使用 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
首先,将身份验证信息(例如用户名和密码)放入 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).