Skip to Content

Mysql search with md5 hashed uuid

Posted on

In my recent project, my users table contains id field with format: 077789a2-a9c6-4bbf-84c3-64c6d016c3a1

For security reasons, clients don’t know exactly user’s id, but they know md5 hashed id. For example, with above id, client will know 453c1c1cb938accbdb360b448788981f string as id.

With users search function, client will send md5 hashed id to server. And the code below is which we use to search user.

  SELECT * from users
      SUBSTR(HEX(, 1, 8),
      SUBSTR(HEX(, 9, 4),
      SUBSTR(HEX(, 13, 4),
      SUBSTR(HEX(, 17, 4),
      SUBSTR(HEX(, 21)
  ) = '453c1c1cb938accbdb360b448788981f'


comments powered by Disqus