The PasswordHasher component provides password hashing utilities.

Overview

PasswordHasher Component

The PasswordHasher component provides secure password hashing utilities.

Getting Started

$ composer require symfony/password-hasher
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;

// Configure different password hashers via the factory
$factory = new PasswordHasherFactory([
    'common' => ['algorithm' => 'bcrypt'],
    'memory-hard' => ['algorithm' => 'sodium'],
]);

// Retrieve the right password hasher by its name
$passwordHasher = $factory->getPasswordHasher('common');

// Hash a plain password
$hash = $passwordHasher->hash('plain'); // returns a bcrypt hash

// Verify that a given plain password matches the hash
$passwordHasher->verify($hash, 'wrong'); // returns false
$passwordHasher->verify($hash, 'plain'); // returns true (valid)

Resources

You might also like...
The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructure and leverage the power of 1Password Secrets Automation

1Password Connect PHP SDK The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructu

A RESTful and extendable Backend as a Service that provides instant backend to develop sites and apps faster, with dead-simple integration for JavaScript, iOS, Android and more.

Welcome to hook ![Gitter](https://badges.gitter.im/Join Chat.svg) hook is a RESTful, extendable Backend as a Service that provides instant backend to

This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for users and tasks resources.
This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for users and tasks resources.

PHP API TO-DO-LIST v.2.0 This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science cours

STEAM education curriculum centered on building a new civilization entirely from trash, which provides all human needs for free directly to the local community

TRASH ACADEMY STEAM(Science Technology Engineering Art Math) education curriculum centered around building self-replicating technology from trash whic

A Statamic Pro addon that provides alternative GraphQL queries for collections, entries and global sets.

Statamic Enhanced GraphQL A Statamic CMS GraphQL Addon that provides alternative GraphQL queries for collections, entries and global sets. ⚠️ This is

The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login

Facebook SDK for PHP (v5) This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app. Installa

A small library that provides functionality to PHP 8.1 enums to act as BitMask flags

PHP Enum BitMask A small library that provides functionality to PHP 8.1 enums to act as BitMask flags. Why? Sometimes you need some flags on the objec

A PHP replacement layer for the C intl extension that also provides access to the localization data of the ICU library.

A PHP replacement layer for the C intl extension that also provides access to the localization data of the ICU library.

Provides tools for building modules that integrate Nosto into your e-commerce platform

php-sdk Provides tools for building modules that integrate Nosto into your e-commerce platform. Requirements The Nosto PHP SDK requires at least PHP v

Comments
  • Fix usage of PasswordHasherAdapter in PasswordHasherFactory

    Fix usage of PasswordHasherAdapter in PasswordHasherFactory

    Using migrate_from with a PasswordEncoderInterface was working fine in Symfony 5.2. It Symfony 5.3, it resulted in an error, because getHasherConfigFromAlgorithm would access it before it is decorated with the adapter.

    Full stack-trace:

    TypeError:
    Argument 1 passed to Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory::createHasher() must be of the type array, object given, called in /var/www/html/vendor/symfony/password-hasher/Hasher/PasswordHasherFactory.php on line 157
    
      at vendor/symfony/password-hasher/Hasher/PasswordHasherFactory.php:73
      at Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory->createHasher(object(LegacyPasswordEncoder), true)
         (vendor/symfony/password-hasher/Hasher/PasswordHasherFactory.php:157)
      at Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory->getHasherConfigFromAlgorithm(array('algorithm' => 'native', 'cost' => 15, 'hash_algorithm' => 'sha512', 'key_length' => 40, 'ignore_case' => false, 'encode_as_base64' => true, 'iterations' => 5000, 'memory_cost' => null, 'time_cost' => null))
         (vendor/symfony/password-hasher/Hasher/PasswordHasherFactory.php:77)
      at Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory->createHasher(array('algorithm' => 'native', 'cost' => 15, 'migrate_from' => array('legacy'), 'hash_algorithm' => 'sha512', 'key_length' => 40, 'ignore_case' => false, 'encode_as_base64' => true, 'iterations' => 5000, 'memory_cost' => null, 'time_cost' => null), true)
         (vendor/symfony/password-hasher/Hasher/PasswordHasherFactory.php:137)
      at Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory->getHasherConfigFromAlgorithm(array('algorithm' => 'native', 'cost' => 15, 'migrate_from' => array('legacy'), 'hash_algorithm' => 'sha512', 'key_length' => 40, 'ignore_case' => false, 'encode_as_base64' => true, 'iterations' => 5000, 'memory_cost' => null, 'time_cost' => null))
         (vendor/symfony/password-hasher/Hasher/PasswordHasherFactory.php:77)
      at Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory->createHasher(array('algorithm' => 'auto', 'cost' => 15, 'migrate_from' => array('legacy'), 'hash_algorithm' => 'sha512', 'key_length' => 40, 'ignore_case' => false, 'encode_as_base64' => true, 'iterations' => 5000, 'memory_cost' => null, 'time_cost' => null))
         (vendor/symfony/password-hasher/Hasher/PasswordHasherFactory.php:113)
      at Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory->createHasherUsingAdapter('App\\Entity\\User')
         (vendor/symfony/password-hasher/Hasher/PasswordHasherFactory.php:65)
      at Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory->getPasswordHasher(object(User))
         (vendor/symfony/security-core/Authentication/Provider/DaoAuthenticationProvider.php:100)
      at Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider->checkAuthentication(object(User), object(UsernamePasswordToken))
         (vendor/symfony/security-core/Authentication/Provider/UserAuthenticationProvider.php:86)
      at Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider->authenticate(object(UsernamePasswordToken))
         (vendor/symfony/security-core/Authentication/AuthenticationProviderManager.php:88)
      at Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager->authenticate(object(UsernamePasswordToken))
         (vendor/symfony/security-http/Firewall/UsernamePasswordFormAuthenticationListener.php:108)
      at Symfony\Component\Security\Http\Firewall\UsernamePasswordFormAuthenticationListener->attemptAuthentication(object(Request))
         (vendor/symfony/security-http/Firewall/AbstractAuthenticationListener.php:136)
      at Symfony\Component\Security\Http\Firewall\AbstractAuthenticationListener->authenticate(object(RequestEvent))
         (vendor/symfony/security-bundle/Debug/WrappedLazyListener.php:49)
      at Symfony\Bundle\SecurityBundle\Debug\WrappedLazyListener->authenticate(object(RequestEvent))
         (vendor/symfony/security-http/Firewall/AbstractListener.php:26)
      at Symfony\Component\Security\Http\Firewall\AbstractListener->__invoke(object(RequestEvent))
         (vendor/symfony/security-bundle/Debug/TraceableFirewallListener.php:62)
      at Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener->callListeners(object(RequestEvent), object(Generator))
         (vendor/symfony/security-http/Firewall.php:86)
      at Symfony\Component\Security\Http\Firewall->onKernelRequest(object(RequestEvent), 'kernel.request', object(TraceableEventDispatcher))
         (vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117)
      at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(RequestEvent), 'kernel.request', object(TraceableEventDispatcher))
         (vendor/symfony/event-dispatcher/EventDispatcher.php:230)
      at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.request', object(RequestEvent))
         (vendor/symfony/event-dispatcher/EventDispatcher.php:59)
      at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(RequestEvent), 'kernel.request')
         (vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:151)
      at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(RequestEvent), 'kernel.request')
         (vendor/symfony/http-kernel/HttpKernel.php:133)
      at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
         (vendor/symfony/http-kernel/HttpKernel.php:79)
      at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
         (vendor/symfony/http-kernel/Kernel.php:199)
      at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
         (public/index.php:20)       
    

    My confguration in security.yml:

        encoders:
            legacy:
                id: 'App\Utils\LegacyPasswordEncoder'
            App\Entity\User:
                algorithm: auto
                cost: 15
                migrate_from:
                    - legacy
    
    opened by peter17 4
Releases(v6.2.0)
  • v6.2.0(Nov 30, 2022)

  • v6.2.0-RC1(Nov 25, 2022)

  • v6.2.0-BETA1(Oct 24, 2022)

    Changelog (https://github.com/symfony/password-hasher/compare/v6.1.6...v6.2.0-BETA1)

    • feature #46183 Hide sensitive information with SensitiveParameter attribute (GromNaN)
    Source code(tar.gz)
    Source code(zip)
  • v6.1.3(Jul 29, 2022)

  • v6.0.11(Jul 29, 2022)

  • v5.4.11(Jul 29, 2022)

  • v6.1.0(May 27, 2022)

  • v6.1.0-RC1(May 14, 2022)

  • v6.1.0-BETA2(Apr 27, 2022)

  • v6.0.8(Apr 27, 2022)

  • v5.4.8(Apr 27, 2022)

  • v6.1.0-BETA1(Apr 15, 2022)

    Changelog (https://github.com/symfony/password-hasher/compare/v6.0.7...v6.1.0-BETA1)

    • feature #45377 Bump minimum version of PHP to 8.1 (nicolas-grekas)
    Source code(tar.gz)
    Source code(zip)
  • v6.0.3(Jan 28, 2022)

  • v5.4.3(Jan 28, 2022)

  • v5.3.14(Jan 28, 2022)

  • v6.0.2(Dec 29, 2021)

  • v5.4.2(Dec 29, 2021)

  • v6.0.1(Dec 9, 2021)

  • v6.0.0(Nov 29, 2021)

  • v5.4.0(Nov 29, 2021)

  • v6.0.0-RC1(Nov 24, 2021)

  • v5.4.0-RC1(Nov 24, 2021)

  • v6.0.0-BETA1(Nov 5, 2021)

    Changelog (https://github.com/symfony/password-hasher/compare/v5.3.10...v6.0.0-BETA1)

    • feature #43653 Add autocompletion for security commands (noniagriconomie)
    • feature #41613 Remove everything related to the deprecated authentication manager (wouterj)
    • feature #41960 Remove legacy password encoders (chalasr)
    • feature #41282 Bump Symfony 6 to PHP 8 (nicolas-grekas)
    Source code(tar.gz)
    Source code(zip)
  • v5.4.0-BETA1(Nov 5, 2021)

    Changelog (https://github.com/symfony/password-hasher/compare/v5.3.10...v5.4.0-BETA1)

    • feature #43653 Add autocompletion for security commands (noniagriconomie)
    Source code(tar.gz)
    Source code(zip)
  • v5.3.8(Sep 28, 2021)

  • v5.3.7(Aug 30, 2021)

    Changelog (https://github.com/symfony/password-hasher/compare/v5.3.6...v5.3.7)

    • bug #42596 Fix wrong cache directive when using the new PUBLIC_ACCESS attribute (wouterj)
    • bug #42321 Fix usage of PasswordHasherAdapter in PasswordHasherFactory (peter17)
    Source code(tar.gz)
    Source code(zip)
  • v5.3.4(Jul 26, 2021)

  • v5.3.3(Jun 30, 2021)

    Changelog (https://github.com/symfony/password-hasher/compare/v5.3.2...v5.3.3)

    • bug #41755 UserPasswordHasher only calls getSalt when method exists (dbrumann)
    Source code(tar.gz)
    Source code(zip)
  • v5.3.2(Jun 17, 2021)

    Changelog (https://github.com/symfony/password-hasher/compare/v5.3.1...v5.3.2)

    • bug #41678 Fix missing PasswordHasherAwareInterface allowed type (chalasr)
    • bug #41572 Prevent PHP fatal error when using auto algorithm (matason)
    Source code(tar.gz)
    Source code(zip)
  • v5.3.0(May 31, 2021)

The Yaml component loads and dumps YAML files.

Yaml Component The Yaml component loads and dumps YAML files. Resources Documentation Contributing Report issues and send Pull Requests in the main Sy

Symfony 3.5k Dec 30, 2022
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder

PoP PoP is a monorepo containing several projects. The GraphQL API for WordPress plugin GraphQL API for WordPress is a forward-looking and powerful Gr

Leonardo Losoviz 265 Jan 7, 2023
Fork of Symfony Rate Limiter Component for Symfony 4

Rate Limiter Component Fork (Compatible with Symfony <=4.4) The Rate Limiter component provides a Token Bucket implementation to rate limit input and

AvaiBook by idealista 4 Apr 19, 2022
Enter-to-the-Matrix-with-Symfony-Console - Reproduction of the "Matrix characterfall" effect with the Symfony Console component.

Enter to the Matrix (with Symfony Console) Reproduction of the "Matrix characterfall" effect with the Symfony Console component. Run Clone the project

Yoan Bernabeu 23 Aug 28, 2022
The BrowserKit component simulates the behavior of a web browser

BrowserKit Component The BrowserKit component simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms

Symfony 2.7k Dec 29, 2022
The server component of API Platform: hypermedia and GraphQL APIs in minutes

API Platform Core API Platform Core is an easy to use and powerful system to create hypermedia-driven REST and GraphQL APIs. It is a component of the

API Platform 2.2k Dec 27, 2022
Stepup Middleware - This component is part of "Step-up Authentication as-a Service".

Step-up Middleware This component is part of "Step-up Authentication as-a Service". See Stepup-Deploy for an overview and installation instructions fo

OpenConext 4 Nov 2, 2022
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder

PoP PoP is a monorepo containing several projects. The GraphQL API for WordPress plugin GraphQL API for WordPress is a forward-looking and powerful Gr

Leonardo Losoviz 265 Jan 7, 2023
This bundle provides tools to build a complete GraphQL server in your Symfony App.

OverblogGraphQLBundle This Symfony bundle provides integration of GraphQL using webonyx/graphql-php and GraphQL Relay. It also supports: batching with

Webedia - Overblog 720 Dec 25, 2022
Provides a Middleware to integration Tideways into Symfony Messenger Processing

Tideways Middleware for Symfony Messenger This package is currently under development and might be moved into the Tideways PHP Extension or stay indep

Tideways 6 Jul 5, 2022