php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76013 Add simple hashes support in password_verify
Submitted: 2018-02-26 17:45 UTC Modified: 2018-02-27 13:27 UTC
From: anrdaemon at freemail dot ru Assigned:
Status: Wont fix Package: hash related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: anrdaemon at freemail dot ru
New email:
PHP Version: OS:

 

 [2018-02-26 17:45 UTC] anrdaemon at freemail dot ru
Description:
------------
If only password_verify could support regular md5/sha1 hashes, it would make hell of a jumpstart for old applications migrating to new hashing schemes.

Test script:
---------------
<?php

$pass = 'MyCoolPass';
$md5 = md5($pass);
$sha1 = sha1($pass);
$crypt = crypt($pass);
$crypts = crypt($pass, (string)rand());
$hash = password_hash($pass, PASSWORD_DEFAULT);
var_dump(
  password_get_info($md5), password_get_info($sha1),
  password_get_info($crypt), password_get_info($crypts),
  password_get_info($hash),
  password_verify($pass, $md5), password_needs_rehash($md5, PASSWORD_DEFAULT),
  password_verify($pass, $sha1), password_needs_rehash($sha1, PASSWORD_DEFAULT),
  password_verify($pass, $crypt), password_needs_rehash($crypt, PASSWORD_DEFAULT),
  password_verify($pass, $crypts), password_needs_rehash($crypts, PASSWORD_DEFAULT),
  password_verify($pass, $hash), password_needs_rehash($hash, PASSWORD_DEFAULT)
);


Expected result:
----------------
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)

Actual result:
--------------
bool(false)
bool(true)
bool(false)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-27 11:12 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2018-02-27 11:12 UTC] cmb@php.net
How is this supposed to work?  The hashes supported by the
password_*() functions clearly identify the hash algorithm
(including any options), and also contain the salt that has been
used to produce the hash. While it would be possible to guess the
algorithm for "plain hashes" (I doubt that this would be a good
idea, though), the salt would be unknown.
 [2018-02-27 12:49 UTC] anrdaemon at freemail dot ru
md5 and sha1 hashes have well known lengths. I presume the length of the passed buffer is readily available, so you don't have to manually count bytes each time you want to know it.
If no hashing signatures were found in a string, and the length is matching one of the two known values, try to use appropriate plain hashing function.

This is not related to salted plain hashes, if anybody was using such a trick, it's up to them to sort the mess they have created.

This is only limited to hashing functions natively provided by PHP (both md5 and sha1 availability predates PHP5). If anybody was using extensions, or database functions, this is out of scope of the proposal.

This proposal does not include CRC32(the only other string hashing option available). A joke is too severe to seriously consider it as password hashing algo.
 [2018-02-27 13:17 UTC] cmb@php.net
-Status: Feedback +Status: Open -Assigned To: cmb +Assigned To:
 [2018-02-27 13:17 UTC] cmb@php.net
Thanks for the clarification.  While I am not supportive of this
proposal (are there still apps which use unsalted SHA1 or even MD5
password hashes?), others may be.
 [2018-02-27 13:27 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2018-02-27 13:27 UTC] nikic@php.net
Let me cut this short by saying that we are definitely not going to implement this. Please manually perform a length check, using your specific application knowledge of the used hash function.

Not everything that has the length of an md5 or sha1 hash is a simple md5 or sha1 hash (to get a basic impression of the stupidity people come up with, see https://hashcat.net/wiki/doku.php?id=example_hashes) and it's not PHP's job to guess at this, especially not in security components.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 17:01:33 2024 UTC