/api/path/to/{token}/
"$ 2a $ 10 $ NebCQ8BD7xOa82nkzRGA9OEh./zhBOPcuV98vpOKBKK6ZTFuHtqlK"
这将中断路由.
所以我想知道基于Golang中的电子邮件生成一些唯一的16-32个字符的字母数字令牌的最佳方法是什么?
So I'm wondering what is the best way to generate some unique 16-32 character alphanumeric tokens based on emails in Golang?
推荐答案
如前所述,您做错了,这是非常不安全的.
As it was already mentioned you are doing it wrong and this is super insecure.
- 使用加密软件包生成安全令牌.此令牌是完全随机的,不与任何电子邮件关联.
func GenerateSecureToken(length int) string {
b := make([]byte, length)
if _, err := rand.Read(b); err != nil {
return ""
}
return hex.EncodeToString(b)
}
- 创建将该令牌映射到用户标识符并在API请求期间对其进行验证的数据库表.
这篇关于如何在Golang中生成唯一的随机字母数字标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!