Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71989 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62309 invoked from network); 2 Feb 2014 10:27:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2014 10:27:32 -0000 Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.171 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.216.171 mail-qc0-f171.google.com Received: from [209.85.216.171] ([209.85.216.171:55841] helo=mail-qc0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AC/D7-30967-29D1EE25 for ; Sun, 02 Feb 2014 05:27:30 -0500 Received: by mail-qc0-f171.google.com with SMTP id n7so9716639qcx.30 for ; Sun, 02 Feb 2014 02:27:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=XmAi3SOTe0QOjzE9jZuH+LPH+34ggw+TZ2PLKhKlrxg=; b=MQNYk9a9cJ1Q2hvxa3A6V7ityRxLJXdzn7YdnTkcMfizL0BHVnn3EEs8nP9cpaZdIe QvY+c9AOWNEtuscma1GnRX0E132YW1dG9m7FTXTCOyzf0StsJs+Xka9b4ZbMjSiTJthQ mVUGOeH1rSW8B+Od7hjmWqDb5i8uHsJCqp+GKAkzmEHM2LJET3auf+1W7vdlaMPCuIhb ht+88fyjwN1UciwLHc7otNUjDtJR0z3uj3Ebp35FJf4wTmwoTlM0KJD32m8eOdiQ/yJb yyz0ShR07I2QKtWYIpyxCFG2ELFDraj3vl8g3WFMNFkuE+D98TNhATwNYO5x+fe8xURf izEQ== MIME-Version: 1.0 X-Received: by 10.224.128.4 with SMTP id i4mr47435969qas.63.1391336847557; Sun, 02 Feb 2014 02:27:27 -0800 (PST) Received: by 10.140.18.129 with HTTP; Sun, 2 Feb 2014 02:27:27 -0800 (PST) In-Reply-To: References: <52EDF552.4010208@divbyzero.net> Date: Sun, 2 Feb 2014 11:27:27 +0100 Message-ID: To: Yasuo Ohgaki Cc: Martin Jansen , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Extending uniqid() or not? From: pierre.php@gmail.com (Pierre Joye) On Sun, Feb 2, 2014 at 11:12 AM, Yasuo Ohgaki wrote: > On Sun, Feb 2, 2014 at 4:35 PM, Martin Jansen wrote: > >> On 02.02.14 05:32, Yasuo Ohgaki wrote: >> > string safe_uniqid([ing $length=64]) >> > >> > It generate ID using good RNG such as /dev/urandom, /dev/arandom for >> > UNIXes, openssl RNG for Windows when they are available. It does not use >> > hash function, but simply convert RNG binary data into text. The same >> > algorithm that is used for session ID may be used. (Use >> > hash_bits_per_character=5, since it only contains alphanumeric chars) >> Since >> > it does not use hash, it's fast. >> > >> > Any comments? Any good names? >> >> The documentation for uniqid() is pretty clear about the fact that it's >> not cryptographically secure and recomends openssl_random_pseudo_bytes() >> as a replacement. Shouldn't we just try to come up with sane default >> values for its $length parameter instead of adding yet another new >> function? >> > > I added the warning to the doc recently. As far as I remember there was always a note about the non secure usage uniqid. That's not something new, or am I mistaken? > I see codes that uses uniqid() as a source of safe unique id generation > using > hash functions which is not secure in fact. Right, I see many insecure codes out there, even things like unfiltered input usage. It does mean we can enable default filter per default, f.e. > We are better to provide easy to use safe unique ID generation function to > prevent this kind of usage even if user could do in user land. Writing a > portable one is not simple enough. We have one, http://de2.php.net/manual/en/function.openssl-random-pseudo-bytes.php. It depends on openssl, but it is safe for the cases defined in your other thread about session. On windows it is even always crypto safe. >> string safe_uniqid([ing $length=64]) Besides the question about the need to add another function, I would not use the word "safe" in any function name :) >> P.S. Is anyone working UUID? PostgreSQL is using OSSP's UUID lib, it's >> good >> > for PHP. >> > http://www.postgresql.org/docs/9.2/interactive/uuid-ossp.html >> >> There's http://pecl.php.net/package/uuid. > > > It uses ext2 UUID. Isn' it only available for linux, is it? > It' a LGPL license also. It's not preferred license for core... As long as it is not bundled, there is no big deal. And it should not be lgpl v3, this license is a mess :) Cheers, -- Pierre @pierrejoye | http://www.libgd.org