Symfony2 usersecurityencoder implements its own authentication method

Source: Internet
Author: User
Fosuserbundle uses sha512 Encryption by default. If you want to implement your own encryption method, you must inherit symfony \ component \ SECURITY \ core \ encoder \ basepasswordencoder <? Phpnamespace Mc \ adminbundle \ SECURITY \ encoder; Use symfony \ component \ SECURITY \ core \ encoder \ basepasswordencoder; Use symfony \ component \ securitycore \ exception \ badcredentialsexception; class joomlapasswordencoder extends basepasswordencoder {private $ cost; public function _ construct ($ cost) {$ cost = intval ($ cost ); if ($ cost <4 | $ cost> 31) {Throw new \ invalidargumentexception ('cost too long, it must be in the range of 4-31 ');} $ this-> Cost = sprintf ('% 02d', $ cost);} public function encodepassword ($ raw, $ salt = NULL) {if ($ this-> ispasswordtoolong ($ raw) {Throw new badcredentialsexception ('invalid password. ');} return MD5 (MD5 ($ raw ). $ salt);} public function ispasswordvalid ($ encoded, $ raw, $ salt = NULL) {if ($ this-> ispasswordtoolong ($ raw) {return false ;} return MD5 (MD5 ($ raw ). $ salt) ===$ encoded;} and then write the resources/config/services of the Service under the bundle. yml (or XML) adds a service: mc_user.security.core.encoder: Class: Mc \ adminbundle \ SECURITY \ encoder \ joomlapasswordencoder arguments: [6] Or dependencyinjection/configuration. add parameters in PHP: $ rootnode-> Children ()-> scalarnode ('cost')-> defaultvalue (6)-> end (); finally, in APP/config/security. in yml, set your own encryption method. Here, the user component is fosuserbundle: Security: encoders: symfony \ component \ SECURITY \ core \ User: plaintext Fos \ userbundle \ model \ userinterface: ID: mc_user.security.core.encoder the ID here is the service name mc_user.encoderdone

 

Symfony2 usersecurityencoder implements its own authentication method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.