Skip to content

Instantly share code, notes, and snippets.

@Zegnat
Created September 8, 2015 17:37
Show Gist options
  • Save Zegnat/b29bba931a80f1e33877 to your computer and use it in GitHub Desktop.
Save Zegnat/b29bba931a80f1e33877 to your computer and use it in GitHub Desktop.
Replacement getkirby/toolkit/lib/password.php using PHP 5.5 password_* functions and paragonie/password_lock inspired SHA512 pre-hashing to support passwords with more than 72 characters.
<?php
class Password {
static public function hash($plaintext) {
return password_hash(base64_encode(hash('sha512', $plaintext, true)), PASSWORD_DEFAULT);
}
static public function isHash($hash) {
$info = password_get_info($hash);
return $info['algo'] !== 0;
}
static public function check($plaintext, $hash) {
return password_verify(base64_encode(hash('sha512', $plaintext, true)), $hash);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment