Hash of unique value = unique hash?

Posted by Nebs on Stack Overflow See other posts from Stack Overflow or by Nebs
Published on 2010-05-04T19:04:00Z Indexed on 2010/05/04 19:08 UTC
Read the original article Hit count: 491

Filed under:
|
|
|
|

Theoretically does hashing a unique value yield a unique value?

Let's say I have a DB table with 2 columns: id and code. id is an auto-incrementing int and code is a varchar. If I do ...

$code = sha1($id);

... and then store $code into the same row as $id. Will my code column be unique as well?

What about if I append the current time? eg:

$code = sha1($id . time());

Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about hash