Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
      • Traits
    • Reflection
    • Security
    • Tokenizer
    • Utils
  • Tracy
    • Bridges
      • Nette
  • none

Classes

  • Identity
  • Passwords
  • Permission
  • SimpleAuthenticator
  • User

Interfaces

  • IAuthenticator
  • IAuthorizator
  • IIdentity
  • IResource
  • IRole
  • IUserStorage

Exceptions

  • AuthenticationException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (https://nette.org)
 5:  * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
 6:  */
 7: 
 8: namespace Nette\Security;
 9: 
10: use Nette;
11: 
12: 
13: /**
14:  * Passwords tools.
15:  */
16: class Passwords
17: {
18:     use Nette\StaticClass;
19: 
20:     /** @deprecated */
21:     const BCRYPT_COST = 10;
22: 
23: 
24:     /**
25:      * Computes salted password hash.
26:      * @param  string
27:      * @param  array with cost (4-31)
28:      * @return string  60 chars long
29:      */
30:     public static function hash($password, array $options = [])
31:     {
32:         if (isset($options['cost']) && ($options['cost'] < 4 || $options['cost'] > 31)) {
33:             throw new Nette\InvalidArgumentException("Cost must be in range 4-31, $options[cost] given.");
34:         }
35: 
36:         $hash = password_hash($password, PASSWORD_BCRYPT, $options);
37:         if ($hash === false || strlen($hash) < 60) {
38:             throw new Nette\InvalidStateException('Hash computed by password_hash is invalid.');
39:         }
40:         return $hash;
41:     }
42: 
43: 
44:     /**
45:      * Verifies that a password matches a hash.
46:      * @return bool
47:      */
48:     public static function verify($password, $hash)
49:     {
50:         return password_verify($password, $hash);
51:     }
52: 
53: 
54:     /**
55:      * Checks if the given hash matches the options.
56:      * @param  string
57:      * @param  array with cost (4-31)
58:      * @return bool
59:      */
60:     public static function needsRehash($hash, array $options = [])
61:     {
62:         return password_needs_rehash($hash, PASSWORD_BCRYPT, $options);
63:     }
64: }
65: 
Nette 2.4-20180918 API API documentation generated by ApiGen 2.8.0