Last active
May 17, 2017 21:28
-
-
Save adelarcubs/482303ddc20e906337f25a07fdac5af2 to your computer and use it in GitHub Desktop.
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 | |
$userEmail = 'test@test.com'; | |
$userPassword = '123456'; | |
// Using Doctrine for example | |
$user = $repository->findByEmail($userEmail); | |
if(!$user) { | |
// User not found | |
// LOGIN ERROR | |
} | |
// Will be removed | |
if(md5($userPassword) == $user->getPassword()) { | |
// encrypt correctly | |
$options = ['cost' => 10]; | |
$hash = password_hash($userPassword, PASSWORD_DEFAULT, $options); | |
// save $hash as a NEW password on database | |
// DO LOGIN | |
} | |
if(password_verify($userPassword, $user->getPassword())) { | |
$options = ['cost' => 10]; | |
if(password_needs_rehash($user->getPassword(), PASSWORD_DEFAULT, $options)) { | |
$hash = password_hash($userPassword, PASSWORD_DEFAULT, $options); | |
// save $hash as a NEW password on database | |
} | |
// DO LOGIN | |
} | |
// LOGIN ERROR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment