1
0

ihasher.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCP\Security;
  23. /**
  24. * Class Hasher provides some basic hashing functions. Furthermore, it supports legacy hashes
  25. * used by previous versions of ownCloud and helps migrating those hashes to newer ones.
  26. *
  27. * The hashes generated by this class are prefixed (version|hash) with a version parameter to allow possible
  28. * updates in the future.
  29. * Possible versions:
  30. * - 1 (Initial version)
  31. *
  32. * Usage:
  33. * // Hashing a message
  34. * $hash = \OC::$server->getHasher()->hash('MessageToHash');
  35. * // Verifying a message - $newHash will contain the newly calculated hash
  36. * $newHash = null;
  37. * var_dump(\OC::$server->getHasher()->verify('a', '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', $newHash));
  38. * var_dump($newHash);
  39. *
  40. * @package OCP\Security
  41. */
  42. interface IHasher {
  43. /**
  44. * Hashes a message using PHP's `password_hash` functionality.
  45. * Please note that the size of the returned string is not guaranteed
  46. * and can be up to 255 characters.
  47. *
  48. * @param string $message Message to generate hash from
  49. * @return string Hash of the message with appended version parameter
  50. */
  51. public function hash($message);
  52. /**
  53. * @param string $message Message to verify
  54. * @param string $hash Assumed hash of the message
  55. * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
  56. * @return bool Whether $hash is a valid hash of $message
  57. */
  58. public function verify($message, $hash, &$newHash = null);
  59. }