Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60813 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19788 invoked from network); 13 Jun 2012 21:44:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jun 2012 21:44:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=gwynne@darkrainfall.org; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=gwynne@darkrainfall.org; sender-id=pass Received-SPF: pass (pb1.pair.com: domain darkrainfall.org designates 209.85.161.170 as permitted sender) X-PHP-List-Original-Sender: gwynne@darkrainfall.org X-Host-Fingerprint: 209.85.161.170 mail-gg0-f170.google.com Received: from [209.85.161.170] ([209.85.161.170:42006] helo=mail-gg0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D1/76-08889-2D909DF4 for ; Wed, 13 Jun 2012 17:44:50 -0400 Received: by ggnf2 with SMTP id f2so998253ggn.29 for ; Wed, 13 Jun 2012 14:44:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-gm-message-state; bh=KvIZjjeyl4BTudFu/Az6bNBPqUmBTciB7LWLE9sV4Aw=; b=cB7DMKyPA5v53DpsH8jy+C8+wEb4cbb5Tjj9LmPjaLT+GHHnFEgPMPgu13A+IRJubi 8kUscMfwUGiOoU1AaV05jl3izyc6DBR+6tlRUSbkI+GTNi0+D/8IM56uCmG1PumQBU3v 0o92QN1ECq66xaHzfVUsbMRpUcB/MLfZTavIm0pIjPBFj3HoHeFCjBWiiN0cMOj+eUjJ 0wVw5DGz5k4j7QvvLUTsUaRQjlCOlxAx0DSxjDKxRXoeItWSeJnjIeNbuuK1eXPvsRzx CAtPLOXSjgUVrHeaBgAAR3o326aMufLQmGUNe6p1ibxbVaiTh+iQ8Uco/6SfpImX2Y7N Tk7A== Received: by 10.236.190.6 with SMTP id d6mr35783020yhn.16.1339623887831; Wed, 13 Jun 2012 14:44:47 -0700 (PDT) Received: from mail-ob0-f170.google.com (mail-ob0-f170.google.com [209.85.214.170]) by mx.google.com with ESMTPS id j39sm6969829ani.3.2012.06.13.14.44.46 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 13 Jun 2012 14:44:47 -0700 (PDT) Received: by obbuo13 with SMTP id uo13so1638359obb.29 for ; Wed, 13 Jun 2012 14:44:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.47.66 with SMTP id b2mr26220809obn.2.1339623886493; Wed, 13 Jun 2012 14:44:46 -0700 (PDT) Received: by 10.182.59.38 with HTTP; Wed, 13 Jun 2012 14:44:46 -0700 (PDT) In-Reply-To: References: Date: Wed, 13 Jun 2012 17:44:46 -0400 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQk+Q+xFxG6v56tWDOPD3KGRtrEcXVw1p3GVLwyPG8saDCmAgy/26t84YoxhWCFHwTT5n8yy Subject: Re: [PHP-DEV] Adding a simple API for secure password hashing? From: gwynne@darkrainfall.org (Gwynne Raskind) On Wed, Jun 13, 2012 at 5:31 PM, Nikita Popov wrote: > Hi internals! > > Recent incidents have shown that even very large websites still don't > get how to do password hashing properly. The sha1 hashes used by > Linkedin et al can be easily cracked even by amateurs without special > hardware. > > What could be the reason for this? Why don't people use bcrypt? It is > being recommended already for *years*, but still most people don't > seem to make use of it. > > I think the reason is that it is incredibly hard to use crypt() > correctly, mainly for the following reasons: > > * For many people the syntax is hard to grasp. The hashing algorithm > is specified as the salt parameter, which is somewhat non-obvious (at > least for me). > * The fact that you verify a password using $hash == crypt($password, > $hash) is equally non-obvious. > * Generating correct salts for bcrypt is quite complicated. It is > encoded in some strange base64 format, thus requiring an additional > function to create it. Additionally it isn't particularly easy to > fetch the random bytes for the salt as you have to check several > possibilities for a cross-platform solution (mcrypt initialization > vector, openssl, /dev/*random, mt_rand etc). > > Correctly hashing a password with bcrypt thus requires about a hundred > lines of code. So one either has to import a library (and strangely it > seems that people don't like to do that!) or has to roll your own > (usually implementing some part incorrectly...) > > Obviously it's somewhat tempting to use a one-liner sha1() hash > instead of a hundred line bcrypt hash. > > So, wouldn't it be better if PHP provided an easy to use API for > secure password hashes natively? So you just have to call a single > function, which magically handles everything for you (like salt > generation). > > A simple sample API could be two functions password_hash($password) > and password_hash_verify($password, $hash). But it could just as well > be a fancy, extensible OOP API. > > I think this would greatly improve the hashing situation for PHP. > > Thanks, > Nikita Strong +1 on this. I'd suggest writing an RFC. -- Gwynne