douyi4205 2014-08-18 02:24
浏览 149
已采纳

在Yii中为users表创建唯一的随机令牌字符串

I am working on a Yii app that requires the 'users' table to have a column 'token' that will need to be a unique random string that is based upon that user in the table (eg there will never be the same token twice).

Can anyone give me some tips on doing this, or are there a Yii component/extension/generator already setup to do this.

Also - what is the most optimised db column type for this?

  • 写回答

2条回答 默认 最新

  • duangan4406 2014-08-18 03:43
    关注

    I suggest just to use hash, that produces long string and use some very unique string to be hashed:

    sha512($userName.time().rand(1000, 9999));
    

    Some PHP hash algorithms lengths

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部