subversion://[vpntest]/release/2.0/WWW/lib/auth_sc.php Log in
ViewVC logotype

Annotate of /release/2.0/WWW/lib/auth_sc.php

Parent Directory Parent Directory | Revision Log Revision Log

Revision 9 - (show annotations) (download) (as text)
Sun Feb 17 15:07:41 2008 MSK (12 years, 9 months ago) by vitalif
File MIME type: text/plain; charset=windows-1251
File size: 3714 byte(s)
Release 2.0

1 <?php
2
3 ///////////////////////////////////////////////////////////
4 // Аутентификация через сессии И куки //
5 // //
6 //////////// (c) 2006, Виталий Филиппов [VMX] ////////////
7 ////////////////////////////////////////
8
9 require_once 'config.php';
10 require_once 'auth_ver.php';
11
12 global $auth_loaded;
13 $auth_loaded = true;
14 ////////////////////////////////////////////////////////////////////////////////////////////
15 // Попытка входа как username:password. Возвращает true или false (успешно или неуспешно) //
16 function set_auth ($username, $password)
17 {
18 global $Domain, $VLoginSession;
19 $password = md5($password);
20 $userid = -1;
21 $userlevel = -1;
22 $displayname = '';
23 if (!auth_verify ($username, $password, $userid, $userlevel, $displayname))
24 return false;
25 // Начало сессии
26 @session_destroy ();
27 session_name ($VLoginSession);
28 session_set_cookie_params (-1, '/', '.' . $Domain);
29 @session_start ();
30 $_SESSION['UserID'] = $userid;
31 $_SESSION['UserName'] = $username;
32 $_SESSION['UserLevel'] = $userlevel;
33 $_SESSION['UserH'] = $password;
34 $_SESSION['UserDName'] = $displayname;
35 //print_r ($_SESSION);
36 return true;
37 }
38 function get_auth_displayname ()
39 {
40 global $Domain, $VLoginSession;
41 session_name ($VLoginSession);
42 session_set_cookie_params (-1, '/', '.' . $Domain);
43 @session_start ();
44 if (isset($_SESSION['UserID']) &&
45 isset($_SESSION['UserName']) &&
46 isset($_SESSION['UserH']) &&
47 isset($_SESSION['UserLevel']) &&
48 isset($_SESSION['UserDName']))
49 return $_SESSION['UserDName'];
50 return false;
51 }
52 // ID вошедшего пользователя или -1 если не вошёл
53 function get_auth_id ()
54 {
55 global $Domain, $VLoginSession;
56 session_name ($VLoginSession);
57 session_set_cookie_params (-1, '/', '.' . $Domain);
58 @session_start ();
59 $userid = -1;
60 $userlevel = -1;
61 $displayname = '';
62 if (isset($_SESSION['UserID']) &&
63 isset($_SESSION['UserName']) &&
64 isset($_SESSION['UserH']) &&
65 isset($_SESSION['UserLevel']) &&
66 auth_verify ($_SESSION['UserName'], $_SESSION['UserH'], $userid, $userlevel, $displayname))
67 return $userid;
68 return -1;
69 }
70 // Имя вошедшшего пользователя или false если не вошёл
71 function get_auth_name ()
72 {
73 global $Domain, $VLoginSession;
74 $userid = -1;
75 $userlevel = -1;
76 $displayname = '';
77 session_name ($VLoginSession);
78 session_set_cookie_params (-1, '/', '.' . $Domain);
79 @session_start ();
80 if (isset($_SESSION['UserID']) &&
81 isset($_SESSION['UserName']) &&
82 isset($_SESSION['UserH']) &&
83 isset($_SESSION['UserLevel']) &&
84 auth_verify ($_SESSION['UserName'], $_SESSION['UserH'], $userid, $userlevel, $displayname))
85 return $_SESSION['UserName'];
86 return false;
87 }
88 // Уровень прав вошедшего пользователя или -1 если не вошёл
89 function get_auth_level ()
90 {
91 global $Domain, $VLoginSession;
92 $userid = -1;
93 $userlevel = -1;
94 $displayname = '';
95 session_name ($VLoginSession);
96 session_set_cookie_params (-1, '/', '.' . $Domain);
97 @session_start ();
98 if (isset($_SESSION['UserID']) &&
99 isset($_SESSION['UserName']) &&
100 isset($_SESSION['UserH']) &&
101 isset($_SESSION['UserLevel']) &&
102 auth_verify ($_SESSION['UserName'], $_SESSION['UserH'], $userid, $userlevel, $displayname))
103 return $userlevel;
104 return -1;
105 }
106 // Очистка аутентификационных данных
107 function clean_auth ()
108 {
109 global $Domain, $VLoginSession;
110 session_name ($VLoginSession);
111 session_set_cookie_params (-1, '/', '.' . $Domain);
112 @session_start ();
113 $_SESSION[] = array();
114 if (isset($_COOKIE[session_name()]))
115 @setcookie(session_name(), '', time()-42000, '/', '.' . $Domain, 0);
116 @session_destroy ();
117 }
118
119 ?>