note 78235 deleted from function.mt-rand by cmb
| From: | cmb@php.net | Date: | Sun, 31 Mar 2019 08:35:25 +0000 |
| Subject: | note 78235 deleted from function.mt-rand by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210460@lists.php.net to get a copy of this message | ||
Note Submitter: bradpeabody at scientology dot net
----
[Editorial note: This suggested "security" improvement simply punts the issue to the
operating system: there is no guarantee that the operating system will work any better than the
Mersenne twister (although it may have more entropy available)]
If you want some random text that is more secure than what can get from a built in PHP method, you
can simply do:
<?php
$myRandomText = shell_exec('head -c 128 < /dev/urandom');
?>
That will get around the fact that rand() and mt_rand() are a bad place to start generating
something that is supposed to be cryptographically secure.
The only down sides to this that I see are:
a) Ugly
b) Slow (have to launch external processes)
c) Not portable (can't do this on Windows)
But if you can live with that, this will be much more secure than using rand() or mt_rand().
- Brad