"Fossies" - the Fresh Open Source Software Archive

Member "proma-0.8.3/libs/auth.lib.php" (25 Oct 2007, 2088 Bytes) of package /linux/privat/old/proma-0.8.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 
    3 /* ProMA (ProFTPd MySQL Admin), Copyright (C) 2002-2007 Stein Magnus Jodal
    4  * ProMA comes with ABSOLUTELY NO WARRANTY.
    5  * This is free software, and you are welcome to redistribute it
    6  * under the terms of the GNU General Public License.
    7  * Read 'COPYING' for further information.
    8  */
    9 
   10 /* ProMA Authorization Library
   11  * $Id: auth.lib.php,v 1.5 2007/10/25 19:13:35 jodal Exp $
   12  */
   13 
   14 function login()
   15 {
   16 // Performs the login and the initial creation of the cookie
   17 
   18     global $_POST, $users_userid, $users_passwd, $users_admin, $table_users;
   19 
   20     $userid = addslashes($_POST["userid"]);
   21     $passwd = addslashes($_POST["passwd"]);
   22 
   23     $query = "SELECT
   24             $users_userid,
   25             $users_passwd
   26         FROM
   27             $table_users
   28         WHERE
   29             $users_admin    = 1 AND
   30             $users_userid = '$userid' AND
   31             $users_passwd = PASSWORD('$passwd')";
   32     $result = mysql_query($query) or die("Failed to query database.");
   33     $row = mysql_fetch_assoc($result);
   34 
   35     $cookie_array["userid"] = $row[$users_userid];
   36     $cookie_array["password"] = $row[$users_passwd];
   37 
   38     $cookie_value = serialize($cookie_array);
   39     setcookie("proma", $cookie_value, time()+3600);
   40 
   41     $is_admin = mysql_num_rows($result);
   42     return $is_admin;
   43 }
   44 
   45 function logout()
   46 {
   47 // Logs out by deleting the cookie and setting runlevel to 0
   48 
   49     setcookie("proma", "", time()-3600);
   50 
   51     return 0;
   52 }
   53 
   54 function check_cookie()
   55 {
   56 // Runned every time a page in the admin section is accessed
   57 // Checks if the cookies data matches the database and the user still is admin
   58 // Renews the cookie
   59 
   60     global $_COOKIE, $users_userid, $users_passwd, $users_admin, $table_users;
   61 
   62     $cookie_value = stripslashes($_COOKIE["proma"]);
   63     $cookie_array = unserialize($cookie_value);
   64     setcookie("proma", "", time()-3600);
   65 
   66     $query = "SELECT
   67             $users_userid
   68         FROM
   69             $table_users
   70         WHERE
   71             $users_admin    = 1 AND
   72             $users_userid = '$cookie_array[userid]' AND
   73             $users_passwd = '$cookie_array[password]'";
   74     $result = mysql_query($query) or die("Failed to query database.");
   75     $is_admin = mysql_num_rows($result);
   76 
   77     if ($is_admin) {
   78         setcookie("proma", $cookie_value, time()+3600);
   79     }
   80 
   81     return $is_admin;
   82 }
   83 
   84 ?>