如何使用PHP生成加密安全的随机数? [英] How do you generate cryptographically secure random numbers with PHP?

查看:161
本文介绍了如何使用PHP生成加密安全的随机数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在PHP中安全生成随机数字

以生成用作认证令牌的密码随机字符串,其将绑定到数据库中的会话数据。我们使用PHP,它似乎没有一个合适的随机数生成器内置。我们如何使用php生成一个长度为N的加密安全的随机字符串?

We need to generate a cryptographically random string to use as an authentication token, which will be tied to session data in the database. We are using PHP, which doesn't appear to have a suitable random number generator built-in. How can we generate a cryptographically secure random string of N length using php?

还要注意,由于我们的应用程序的本质,shell_exec不在表中。

Also note, due to the nature of our application, shell_exec is off the table.

推荐答案

uniqid ? docs有一个如何用于cookie /会话的示例。

what about uniqid? docs have an example of how it can be used for cookies/sessions.

这篇关于如何使用PHP生成加密安全的随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆