Created
February 7, 2019 14:22
-
-
Save Nek-/817a367d7ccd15117742d2d3db45dcf1 to your computer and use it in GitHub Desktop.
Symfony LDAP Password encoder example (adapt to *your* LDAP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Security; | |
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface; | |
class LdapEncoder implements PasswordEncoderInterface | |
{ | |
public function encodePassword($raw, $salt) | |
{ | |
return "{SHA}" . base64_encode( pack( "H*", sha1( $raw ) ) ); | |
} | |
public function isPasswordValid($encoded, $raw, $salt) | |
{ | |
$rawEncoded = "{SHA}" . base64_encode( pack( "H*", sha1( $raw ) ) ); | |
return $encoded === $rawEncoded; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment