$id) $id = $user["id"]; /* Now add the user */ $gecos[] = array("id" => ++$id, "login" => $login, "table" => $table, "type" => $type, "password" => crypt($pass, $salt)); /* Now the array $gecos contains the existing users and (encrypted) passwords from the file and the new user (and the encrypted password). */ return store_password($id); } /* Modify a user password */ function modify_user_password($id, $pass, $pass2) { global $gecos; global $salt; if (strlen($pass) == 0) return 0; if ($pass != $pass2) return -1; if (count($gecos)) foreach ($gecos as $key => $user) if ($user["id"] == $id) { $gecos[$key]["password"] = crypt($pass, $salt); return store_password($id); } return -2; } /* Modify a user jsflag */ function modify_user_jsflag($id, $jsflag) { global $gecos; if (count($gecos)) foreach ($gecos as $key => $user) if ($user["id"] == $id) { $gecos[$key]["jsflag"] = $jsflag; return store_password($id); } return 0; } /* Delete a user */ function delete_user($id) { global $gecos; if (count($gecos)) foreach ($gecos as $key => $user) if ($user["id"] == $id) { unset($gecos[$key]); return store_password($id); } return 0; } /* Check if a table already exists */ function is_table($table) { global $gecos; if (count($gecos)) foreach ($gecos as $user) if ($user["table"] == $table) return 1; return 0; } /* Check if an user/password is valid the password file */ function check_user($login, $table, $pass) { global $gecos; if (($login == "") || ($table == "")) return -1; if (count($gecos)) foreach ($gecos as $user) if (($user["login"] == $login) && ($user["table"] == $table)) { if (crypt($pass, $user["password"]) == $user["password"]) return $user["id"]; else return 0; } return -1; } /* Get user */ function get_user($id) { global $gecos; if (count($gecos)) foreach ($gecos as $user) if ($user["id"] == $id) return $user; return NULL; } /* Get user for a table*/ function get_table($table) { global $gecos; $u = array(); if (count($gecos)) foreach ($gecos as $user) if ($user["table"] == $table) $u[] = $user; return $u; } /* Get type */ function get_type($id) { global $gecos; if ($id <= 0) return $id; if (count($gecos)) foreach ($gecos as $key => $user) if ($user["id"] == $id) return $user["type"]; return 0; } /* Initialization */ include($lib_dir.$db_type."/authentification.php"); /* Generate a random salt with letters and/or numbers */ mt_srand((double)microtime()*1000000); $chars = array_merge(range('a','z'),range('A','Z'),range(0,9)); for($i=0;$i<2;$i++) $salt .= $chars[mt_rand(0,count($chars)-1)]; /* Salt $salt created */ ?>