duanhaodi4809 2010-04-02 18:42
浏览 129
已采纳

在MySQL中存储SHA-512哈希

I was wondering if I use PHP's hash() function to generate sha512 hashes how would my MySQL table field look like in-order to be capable of holding the hashed password.

Here is my current MySQL password field layout

char(40)
  • 写回答

1条回答 默认 最新

  • doujiu6976 2010-04-02 18:43
    关注

    A sha512 hash is represented as a 128 characters-long string.

    For example, the following portion of code :

    $sha512 = hash('sha512', "Hello, World!");
    echo strlen($sha512);
    

    Will give this output :

    128
    


    Which means your char(40) is far too small, and that you should use a char(128).


    Another solution would be to store it in a binary form, and not a string -- which would mean 64 bytes.

    But note it might be harder to deal with that representation, in some cases, I suppose.

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

报告相同问题?

悬赏问题

  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源