douliang1900 2017-06-20 14:17
浏览 162
已采纳

条形码id序列:添加随机性

I want to know if my barcode sequence method is sufficiently random and secure. I am currently using a barcode format as follows:

{base36 encoded sequential id}-{4 random numeric characters}

ex.:
2v05-9187
2v06-3607
2v07-1810

I want to switch to all numeric to allow easier keypad entry in the event of unreadable ticket:

34508-4821
34509-9615

It's pretty obvious what's going on here to hackers but it's reasonably secure(?)

I've looked into one-way hash likecrc32 but it produces variable length, longer numbers

echo hexdec(crc32("1000-secret"));
echo '<br>';
echo hexdec(crc32("1001-secret"));

//output:

1076135781
225104646983
  • 写回答

1条回答 默认 最新

  • doujiao3072 2017-06-20 14:38
    关注

    If you just want 4 random numbers your approach will work, just take the first four from your output:

    echo substr(hexdec(crc32("1001-secret")), 0, 4);
    

    With only four numbers you're going to be between 0000-9999, which is 10,000 different options. If this is enough randomity for you you're all set.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable