diff options
author | Simon Rettberg | 2015-03-04 18:43:06 +0100 |
---|---|---|
committer | Simon Rettberg | 2015-03-04 18:43:06 +0100 |
commit | 7b17223904214024018f626715926fa729941d3c (patch) | |
tree | 6d9fd93915726600ed6c430d1e2e64af87528ef1 /inc/crypto.inc.php | |
parent | Third Commit (diff) | |
download | bwlp-webadmin-7b17223904214024018f626715926fa729941d3c.tar.gz bwlp-webadmin-7b17223904214024018f626715926fa729941d3c.tar.xz bwlp-webadmin-7b17223904214024018f626715926fa729941d3c.zip |
Fourth Commit
Diffstat (limited to 'inc/crypto.inc.php')
-rw-r--r-- | inc/crypto.inc.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/inc/crypto.inc.php b/inc/crypto.inc.php new file mode 100644 index 0000000..56f5073 --- /dev/null +++ b/inc/crypto.inc.php @@ -0,0 +1,29 @@ +<?php + +class Crypto +{ + + /** + * Hash given string using crypt's $6$, + * which translates to ~130 bit salt + * and 5000 rounds of hashing with SHA-512. + */ + public static function hash6($password) + { + $salt = substr(str_replace('+', '.', base64_encode(pack('N4', mt_rand(), mt_rand(), mt_rand(), mt_rand()))), 0, 16); + $hash = crypt($password, '$6$' . $salt); + if (strlen($hash) < 60) Util::traceError('Error hashing password using SHA-512'); + return $hash; + } + + /** + * Check if the given password matches the given cryp hash. + * Useful for checking a hashed password. + */ + public static function verify($password, $hash) + { + return crypt($password, $hash) === $hash; + } + +} + |