Home  >  Article  >  Backend Development  >  app token 怎么生成

app token 怎么生成

WBOY
WBOYOriginal
2016-06-06 20:07:511881browse

1 app token现在用的地方比较多,请问一般采用什么方式生成,是比如:时间戳+userid+随机字符串。一般规律是什么?

回复内容:

1 app token现在用的地方比较多,请问一般采用什么方式生成,是比如:时间戳+userid+随机字符串。一般规律是什么?

我觉得token中存储密码什么的不安全,虽然有加密,我的做法是存储随机字符串,数据表中有两个字段,一个是随机字符串,一个是用户id

json web token 已经是一种很完善的规范了。 而且有各种语言里的实现库: https://jwt.io/

真巧,我刚完成一个
我的方法是这样的:
MD5(userid+pwd+time)
然后再维护一个token的列表就可以了,设定时间,定时清除,定时更新
这个做法比较简单,可维护几万到几十万的量

希望对你有帮助

Nodejs直接用的https://www.npmjs.com/package/jsonwebtoken

参考jwt

base64 encode uuid :

<code class="golang">
import (
    "encoding/base64"

    "github.com/satori/go.uuid"
)

func sjmm() string {
    encoder := base64.NewEncoding("NE4NahtY8WgBhvdjKdxvfwe")
    return encoder.EncodeToString(uuid.NewV4().Bytes())
}</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn