PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 18, 2022

[FIXED] Symfony 3 custom user provider using Bcrypt

 January 18, 2022     bcrypt, php, symfony, symfony-3.1, symfony-security     No comments   

Issue

In reading https://symfony.com/doc/current/security/custom_provider.html#create-a-user-class/, all of the examples that I've seen implement the Symfony\Component\Security\Core\User\UserInterface for the User class. This interface defines a method for a salt field - but I'm wanting to use Bcrypt for the hashing algorithm.

In my app/config/security.yml file I have:

encoders:
    AppBundle\Security\User\WebserviceUser:
        algorithm: bcrypt
        cost: 12

The linked document says:

If getSalt() returns nothing, then the submitted password is simply encoded using the algorithm you specify in security.yml. If a salt is specified, then the following value is created and then hashed ...

Does this imply that if I specify for Bcrypt to be used, then I don't need a salt field in the users DB table (since the salt is in the same string as the rest of the password when hashed with Bcrypt)?

If that is the case then I'm guessing that I could just leave the getSalt() method with an empty body so that no salt would be specified and the algorithm in security.yml would be used.

Are my above assumptions correct? If they are not, how can I implement a user provider with bcrypt being used to hash passwords?

I'm using Symfony 3.1.6


Solution

As stated in Creating your First User:

Do you need to use a Salt property?

If you use bcrypt, no. Otherwise, yes. All passwords must be hashed with a salt, but bcrypt does this internally. Since this tutorial does use bcrypt, the getSalt() method in User can just return null (it's not used). If you use a different algorithm, you'll need to uncomment the salt lines in the User entity and add a persisted salt property.

if you want to use Bcrypt just return null in the getSalt() method.



Answered By - gp_sflover
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing