How do you generate cryptographically secure random numbers with PHP?(如何使用 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 生成密码安全的随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 PHP 生成密码安全的随机数?
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
