note 78235 modified in function.mt-rand by ezyang
| From: | ezyang@php.net | Date: | Wed, 03 Oct 2007 23:18:07 +0000 |
| Subject: | note 78235 modified in function.mt-rand by ezyang | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-131050@lists.php.net to get a copy of this message | ||
[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
--was--
If you want some random text that is more secure than what can get from a built in PHP method, you
can simply do:
$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
http://php.net/manual/en/function.mt-rand.php