Initial support for variable hashing alghorithms (currently login-only)
authorHarvie <tomas@mudrunka.cz>
Wed, 1 Dec 2010 03:03:07 +0000 (04:03 +0100)
committerHarvie <tomas@mudrunka.cz>
Wed, 1 Dec 2010 03:03:07 +0000 (04:03 +0100)
doc/TODO
wwwroot/inc/eventz/login.inc

index f61c8f73ea1c8eeb811038924539dbceba5bdffb..95ccf36ac55f8cca2f51948a718051ceebd0a51a 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -50,8 +50,5 @@
 - Switch completely to Base36 (Templates, Links, don't change $_GET[], queries should convert between base10 in db and base36 in kyberia automatically, etc...)
 
 - (IMHO we should use SHA1 or stronger algorithm instead of MD5 for storing passwords)
-  (We can use multiple hash algorithms (so we'll have backward DB compatibility):
-               {SHA256}0654209dbde29a5c17e4f04ab63a91d303d2e7c791c7b5777581a7fa6550054e
-               {SHA1}f67c52c4a27cf05c99e4f3f946d6500f045a4735
-               5b077a0ab90992d9763c5b120b22c9d7
-  ) Harvie
+  (We really need this... I've cracked Hromi's password in few seconds (even when it was relatively secure))
+  (I've implemented this partially. We can now login using various hash algorithms, it's backward compatible, but we still need to edit registration/password changing to use SHA1 when updating passwords in DB)
index c8b5ef8c658873272fec7cd8790d2eb65f655fba..154cdef2d451029112f8ffc110a50bb72ed79ec3 100644 (file)
@@ -4,7 +4,14 @@ function login() {
     global $db,$error,$node_id;
     $login = mysql_real_escape_string($_POST['login']);
     $password = $_POST['password']; // Not SQLi but be carefull
-    $hash = md5($password);
+    $password_hash_algos=array('sha256','sha1','md5'); //List of supported algos can be obtained using: php -r 'print_r(hash_algos());'
+
+    $hash_query='(';
+    foreach($password_hash_algos as $algo) {
+      $hash_query.="password='".hash($algo, $password)."' OR ";
+    }
+    $hash_query.='false )';
+
     $login_type = $_POST['login_type'];
     $referer = $_SERVER['HTTP_REFERER'];
 
@@ -15,7 +22,7 @@ function login() {
 
     switch ($login_type) {
         case "name":
-            $q = "select * from users where login='$login' and password='$hash'";
+            $q = "select * from users where login='$login' and $hash_query";
             $set = $db->query($q);
             $set->next();
             $user_id = $set->getString('user_id');
@@ -27,7 +34,7 @@ function login() {
             // HA! if it is number, escape_string is not enough
            $login=intval($login);
 
-            $q="select * from users where user_id='$login' and password='$hash'";
+            $q="select * from users where user_id='$login' and $hash_query";
             $set=$db->query($q);
             $set->next();
             $user_id=$set->getString('user_id');
This page took 0.142003 seconds and 4 git commands to generate.