Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72025 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42553 invoked from network); 2 Feb 2014 23:55:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2014 23:55:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.179 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.220.179 mail-vc0-f179.google.com Received: from [209.85.220.179] ([209.85.220.179:36619] helo=mail-vc0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8B/96-30967-BDADEE25 for ; Sun, 02 Feb 2014 18:55:08 -0500 Received: by mail-vc0-f179.google.com with SMTP id lh14so4253657vcb.24 for ; Sun, 02 Feb 2014 15:55:05 -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=5BnUZYvHJoFnHuz7sHFOhVhQwWBTWfSdD64nBBbl15Q=; b=jNwAvq6xPvkONP352jgDCMNYfYrpUKRW9C0p5pgn8I++kX6v9vsEexnbtx2HFyiE/5 qZ5S9Z+ynEoynctjIfEQHp/3G7uR2/K2KwvtfpaE070M7twqldLdClVHXKPQ7KBGG0vZ 3j7hxl+LY7gBnbG+V1QwwBYmtl4SkvoeASVSyctsJXaNWmy3gL2TOw3AOhpxZ4aP2SHQ IUT/Zgf20TaqXTtb/6zERHgOe5F63Vg5gFW4pZa1avMG9ltqm8cH0FeA+8tCkPXvez+E 5fyCcRtAP4onDVzr8rdOE96BJluB6XQdjQqopqGRVy5wInaBMoqUS22s/97P2/EpZeLc apXQ== MIME-Version: 1.0 X-Received: by 10.52.109.193 with SMTP id hu1mr22289191vdb.11.1391385305001; Sun, 02 Feb 2014 15:55:05 -0800 (PST) Received: by 10.58.133.229 with HTTP; Sun, 2 Feb 2014 15:55:04 -0800 (PST) In-Reply-To: References: <52EDF552.4010208@divbyzero.net> Date: Mon, 3 Feb 2014 07:55:04 +0800 Message-ID: To: Yasuo Ohgaki Cc: Martin Jansen , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=bcaec548a15bd9b61e04f1752298 Subject: Re: [PHP-DEV] Extending uniqid() or not? From: tjerk.meesters@gmail.com (Tjerk Meesters) --bcaec548a15bd9b61e04f1752298 Content-Type: text/plain; charset=ISO-8859-1 On Sun, Feb 2, 2014 at 6:12 PM, 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. > > I see codes that uses uniqid() as a source of safe unique id generation > using > hash functions which is not secure in fact. > > 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. > > > string safe_uniqid([ing $length=64]) > > Sorry, there is typo and option should be descriptive. It should be > > string safe_uniqid([int $length_of_returned_unique_id_string=64'); > > This function is totally different from current uniqid(). > I don't like the name. I hope some one think of good name for it. > > > 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... > I think it would be good enough to have only uuid v4: function uuidv4() { $data = openssl_random_pseudo_bytes(16); // or whatever $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0010 $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10 return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); } It's really just a representation of random data, whereby 6 bits are used for the actual format. > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > -- -- Tjerk --bcaec548a15bd9b61e04f1752298--