한 가지 방법은 다음과 같습니다
내가 직면 한 문제에 대한 비슷한 질문입니다 사용자 이름을 입력 한 다음 암호를 확인하십시오. 입력 한 사용자 이름에 대한 사용자가 존재하고 입력 된 암호가 해당 사용자의 암호와 일치하면 사용자를 인증하십시오. 예 :
services.yml :
public function userLogin($username, $password)
{
$em = $this->getEntityManager();
$query = $em->createQuery('SELECT u FROM VenomCoreBundle:User u WHERE u.username = :username OR u.email = :username AND u.isDeleted <> 1 ')
->setParameter('username', $username);
try {
$entity = $query->getSingleResult();
if (count($entity) > 0) {
$encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
$passwordEnc = $encoder->encodePassword($password, $entity->getSalt());
$userPassword = $entity->getPassword();
if ($passwordEnc == $userPassword) {
$tokenValue = $entity->getUserToken();
$profile = $entity->getUserProfile();
if(!$profile) {
return false;
}
$userName = $profile->getFullName();
$response = array(
'token' => $tokenValue,
'username' => $userName
);
} else {
return false;
}
}
} catch (\Doctrine\Orm\NoResultException $e) {
return false;
}
return $response;
}
링크 된 질문에 대한 내 대답이 도움이 되었습니까? 아니면 그냥 물건을 혼란 시켰나요? – Cerad
어떤 종류의 웹 서비스를 사용하고 있습니까? 암호는 어떻게 암호화됩니까? 어쩌면 http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html에 설명 된대로 인증 공급자를 만들어야 할 수도 있습니다.하지만 그것은 많은 작업입니다! http://stackoverflow.com/questions/14928514/symfony2-authentication-via-3rd-party-rest-api/14947332#14947332를 확인하십시오. 시작하는 데 도움이 될 것입니다. – hacfi
답장을 보내 주셔서 감사합니다. 나는 @ hacfi가 [here] (http://stackoverflow.com/questions/14928514/symfony2-authentication-via-3rd-party-rest-api/14947332#14947332)라고 제안하는 것처럼 그렇게하려고 노력할 것이다. – SupaCoco