根据用户详细信息在Javascript中创建随机令牌 [英] Create a random token in Javascript based on user details
问题描述
我想创建一个随机字符串(令牌),可用于识别用户,同时避免与任何其他用户的令牌发生任何潜在冲突。
I want to create a random string (token) which can be used to identify a user whilst avoiding any potential conflicts with any other users' tokens.
我是什么我想是一个MD5哈希 navigator.userAgent + new Date()。getTime()
来生成令牌,但需要一个完整的Javascript MD5库来哈希它我不是真的想做。
What I was thinking of was an MD5 hash of navigator.userAgent + new Date().getTime()
to generate the token but that requires a whole Javascript MD5 library to hash it which I don't really want to do.
它必须由AZ / 0-9个字符组成,理想情况下不得超过32个字符。我对所有想法持开放态度。谢谢!
It has to be made up of A-Z/0-9 characters and ideally no longer than 32 characters. I am open to all ideas. Thanks!
为了澄清我不是在寻找任何随机字符串生成器,随机字符串必须通过Javascript提供的用户详细信息生成也花时间避免潜在的冲突!
推荐答案
结帐 crypto.js 项目。它是一系列加密算法。该项目为每个散列算法都有单独的js文件。
Checkout crypto.js project. Its a collection of cryptographic algorithms. The project has separate js files for each hashing algorithms.
这篇关于根据用户详细信息在Javascript中创建随机令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!