summaryrefslogtreecommitdiffstats
path: root/inc/crypto.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2013-10-31 12:38:25 +0100
committerSimon Rettberg2013-10-31 12:38:25 +0100
commita362ac12b119b49519f5af51b92ebb7d6e127b87 (patch)
treea2334426c8af99f864e2dd90c2f275e3ed50083a /inc/crypto.inc.php
parentRemodel zeug mit settings und so (diff)
downloadslx-admin-a362ac12b119b49519f5af51b92ebb7d6e127b87.tar.gz
slx-admin-a362ac12b119b49519f5af51b92ebb7d6e127b87.tar.xz
slx-admin-a362ac12b119b49519f5af51b92ebb7d6e127b87.zip
Comments, minor refactoring, possiblity to validate configuration parameters
Diffstat (limited to 'inc/crypto.inc.php')
-rw-r--r--inc/crypto.inc.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/inc/crypto.inc.php b/inc/crypto.inc.php
new file mode 100644
index 00000000..54cdef8a
--- /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, 22);
+ $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;
+ }
+
+}
+