Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88583 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42157 invoked from network); 30 Sep 2015 20:26:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Sep 2015 20:26:26 -0000 X-Host-Fingerprint: 83.112.245.234 AAubervilliers-652-1-38-234.w83-112.abo.wanadoo.fr Received: from [83.112.245.234] ([83.112.245.234:13415] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/20-38941-E654C065 for ; Wed, 30 Sep 2015 16:26:25 -0400 To: internals@lists.php.net Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes References: Date: Wed, 30 Sep 2015 22:26:05 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: Quoted-Printable Message-ID: User-Agent: Opera Mail/1.0 (Win32) X-Posted-By: 83.112.245.234 Subject: Re: PHP 7.1 - should we add a random_str() function? From: bensor987@neuf.fr ("Benoit Schildknecht") Hi, Le Wed, 30 Sep 2015 18:15:09 +0200, Scott Arciszewski = a =C3=A9crit: > This is probably answerable by a quick yes/no and shouldn't need a ton= > of bikeshedding, but if that happens anyway I apologize in advance. > > I think random_bytes() and random_int() are great; they provide a > much-needed building block in PHP 7.0. However, I do worry a bit that > the most common use for random_int() (generating a random string of a > fixed length with a given character set) will be reinvented over and > over again, and rarely consistently. > > I would propose a random_str() function that behaves similar to this > userland snippet: http://stackoverflow.com/a/32870871/2224584 > > Function prototype: > >> string random_str( int $length, string $charset) > > Would return a string or throw an Error|Exception (e.g. invalid input > parameters, or the operating system's CSPRNG begins to melt). > > I can write up an RFC for this, with a patch targeting 7.1, if anyone > is interested in it. > > Scott Arciszewski > Chief Development Officer > Paragon Initiative Enterprises I'm interested, as I generate random strings for default passwords. I ca= n = stay with my current system, but it would be sweet to shorten my code a = = little bit :) Regards.