April 30, 2012

Trimming hashed password (for user identification)

Question by GARR

http://www.vidyasocks.com/forums.php?id=1&id=1

as you can see at the bottom I am using hash as a way to identify users. How can I trim off the rest after 10 characters?

Answer by Jason Fuerstenberg

Trimming runs the risks of hash collisions where two users potentially share the same trimmed portion.

http://en.wikipedia.org/wiki/Collision_(computer_science)

Hashing algorithms go to great length to avoid this possibility so modification of the hashed results in any way is not recommended.

Answer by Starx

Use substr():

$hash = substr($hash,0,10);

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!