Skip to content

Instantly share code, notes, and snippets.

@adelarcubs
Last active May 17, 2017 21:28
Show Gist options
  • Save adelarcubs/482303ddc20e906337f25a07fdac5af2 to your computer and use it in GitHub Desktop.
Save adelarcubs/482303ddc20e906337f25a07fdac5af2 to your computer and use it in GitHub Desktop.
<?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