Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88581 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30387 invoked from network); 30 Sep 2015 16:15:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Sep 2015 16:15:14 -0000 Authentication-Results: pb1.pair.com smtp.mail=scott@paragonie.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=scott@paragonie.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain paragonie.com from 209.85.215.46 cause and error) X-PHP-List-Original-Sender: scott@paragonie.com X-Host-Fingerprint: 209.85.215.46 mail-la0-f46.google.com Received: from [209.85.215.46] ([209.85.215.46:33191] helo=mail-la0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AE/90-24989-09A0C065 for ; Wed, 30 Sep 2015 12:15:12 -0400 Received: by lahh2 with SMTP id h2so52599986lah.0 for ; Wed, 30 Sep 2015 09:15:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=F4D8exxlb2qjPfHB5V2HY7ENjF82h8tilgyV1Us0n4U=; b=erDpgsrjarCRi0N1tY2s1uZ9nE94FEbnC8lNW2PdZdoD4v0NvEVluogoP6IgbGsifj 55+TGyPwd5hhFGlK8quogQ87N8KB82Do1otwYhAyVth/2sDPW2vVPBLrSYBWGV1Mlncp /UChDkZ+1ZEeNMvf9eE8mPwYpx4Ch9dgw2AwkzXhaRhLY+poi7a1MsXa0sfctq3Nn8X+ vDv07jLnwaHFce8q/+TmIAu9qSGkFkLueO0z5jUGjZBzkYhl3s3BmUOpIhuNuMipEaiW 7Q6rXzpiTtHPD3hyl6nNrnDbobUQuRj9McWI/3WLLc10RU/12DeyqGM6NkmBEtnx6m/t vkJg== X-Gm-Message-State: ALoCoQmiDiLB2XH7/CiFp8An7U5qOXXnrU8li++TRwSqw4H9ULtAW0DIUsd53qCikwtG2oNyHkZM MIME-Version: 1.0 X-Received: by 10.25.153.147 with SMTP id b141mr957353lfe.59.1443629709104; Wed, 30 Sep 2015 09:15:09 -0700 (PDT) Received: by 10.114.79.105 with HTTP; Wed, 30 Sep 2015 09:15:09 -0700 (PDT) Date: Wed, 30 Sep 2015 12:15:09 -0400 Message-ID: To: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: PHP 7.1 - should we add a random_str() function? From: scott@paragonie.com (Scott Arciszewski) 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