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

查看:24
本文介绍了如何使用 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?文档有一个如何将其用于 cookie/会话的示例.

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

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

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