Automatically provide unique id in the database

后端 未结 3 556
無奈伤痛
無奈伤痛 2021-01-26 04:27

In my project i need to register a donor and I need the user to enter his information and the system registers him and generate a unique id to the donor.

3条回答
  •  一向
    一向 (楼主)
    2021-01-26 05:02

    If the donor id has to be used outside mysql, consider the additional usage of UUID() -- http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_uuid (in addition to the integer primary key that is); external interfaces won't be as vulnerable to parameter-playing (e.g. "let's see if I cant't get the data for donor 'my-id + 1'") if the exposed id is a uuid.

    That said, as mentioned in the mysql docs, if you need the uuids to be unpredictable, don't use the UUID()-Function but use e.g. an hash-algorithm (e.g. sha1 ) over the users data and sufficient entropy from the system (urandom, ...)

    Edit: Have a read at wikipedia http://en.wikipedia.org/wiki/Universally_unique_identifier on how to build format a uuid.

提交回复
热议问题