Skip to content

Instantly share code, notes, and snippets.

@Nek-
Created February 7, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nek-/817a367d7ccd15117742d2d3db45dcf1 to your computer and use it in GitHub Desktop.
Save Nek-/817a367d7ccd15117742d2d3db45dcf1 to your computer and use it in GitHub Desktop.
Symfony LDAP Password encoder example (adapt to *your* LDAP)
<?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