PHP5有效的哈希生成与最小(无)碰撞机会 [英] PHP5 effecient hash generation with minimal(no) chance of collision
问题描述
我想将用户数据存储在memcache中,而且我希望能够将用户数据存储在memcache中,而且我希望在这里存储更好的受过良好教育的人员。为用户数据生成一个唯一的。
我最初的想法是使用用户的用户名或其他较少描述性的信息作为某种散列的基础。
我的标准是生成过程将会是 我不确定我的平常武器sha1 / 2是否符合这个标准,所以我在这些问题上鞠躬致意。如果你的用户名是唯一的,那么你为什么不直接使用它们而不是试图生成一些它们已被保证是唯一的。
Cryptology isn't my thing so hopefully there are a few better educated people here than me.
I would like store user data in memcache and I'd like to generate a unique to the user data. My original idea is to use the user's username, or another less descriptive piece of information, as the basis for some kind of hash.
My criteria is that the generation process will be
- fast
- produce the same value given the same input across different servers/environments/php versions
- and have little to no chance of collisions (as this would be catastrophic) given a large number of inputs.
I'm not sure whether my usual weapons, sha1/2, would fit this criteria so I'm bowing to those better verse in these matters. Better safe than sorry.
If your usernames are unique then why don't you use them directly rather than trying to generate some kind of hash?
- They're already guaranteed to be unique.
- They can be used as-is. No extra processing required.
- They'd (probably, on average) be smaller than the corresponding SHA1 hash.
这篇关于PHP5有效的哈希生成与最小(无)碰撞机会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!