Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | <?php |
2 | |||
3 | if (!defined('WBLEGAL')) die('Kann nicht ohne Personal WebBase ausgeführt werden.'); |
||
4 | |||
5 | // TODO: Konfigurierbar machen? |
||
6 | define('COOKIE_VALIDITY', time()+60*60*24*36525); // 100 Jahre gültig |
||
7 | |||
8 | if ($wb_user_type == 0) |
||
9 | { |
||
10 | die($header.'Funktionalität nur für registrierte Benutzer.'.$footer); |
||
11 | } |
||
12 | |||
13 | if ($aktion == 'generate') |
||
14 | { |
||
15 | $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
||
16 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', |
||
17 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', |
||
18 | '.', ',', '$', '#', '!', '?', '=', '~', '*', '/', '\\', '+', '-', '_', '&', '%', '$', '§', '"', "'", ';', ':'); |
||
19 | // TODO: Noch besser: Einfach jedes Nicht-Binärzeichen wählen |
||
20 | |||
21 | $new_secret_key = ''; |
||
22 | for ($i=0; $i<255; $i++) |
||
23 | { |
||
24 | $new_secret_key .= $hex[mt_rand(0, count($hex)-1)]; |
||
25 | } |
||
26 | |||
27 | db_query("UPDATE `".$WBConfig->getMySQLPrefix()."users` SET `fastlogin_serial` = `fastlogin_serial` + 1, `fastlogin_secret` = '".db_escape($new_secret_key)."' WHERE `id` = '".$benutzer['id']."'"); |
||
28 | |||
29 | $benutzer['fastlogin_secret'] = $new_secret_key; |
||
30 | |||
31 | $aktion = 'reget'; |
||
32 | } |
||
33 | |||
34 | if ($aktion == 'reget') |
||
35 | { |
||
36 | function wb_generate_fast_login_key() { |
||
37 | global $wb_user_username, $wb_user_password, $benutzer; |
||
38 | |||
39 | // Angabe der ID verhindert das Durchlaufen der Datenbank zum Suchen des passenden Eintrags |
||
40 | |||
41 | define('WB_FL_DELIM', '@@'); |
||
42 | |||
43 | $secret_key = $wb_user_username."\n"; |
||
44 | $secret_key .= special_hash($wb_user_username)."\n"; |
||
45 | $secret_key .= $wb_user_password."\n"; |
||
46 | $secret_key .= special_hash($wb_user_password); |
||
47 | $secret_key = $benutzer['id'].WB_FL_DELIM.wb_encrypt($secret_key, $benutzer['fastlogin_secret']); |
||
48 | |||
49 | return $secret_key; |
||
50 | } |
||
51 | |||
52 | $secret_key = wb_generate_fast_login_key(); |
||
53 | |||
54 | wbSetCookie('wb_fastlogin_key', $secret_key, COOKIE_VALIDITY); |
||
55 | |||
56 | wb_redirect_now($_SERVER['PHP_SELF'].'?seite=main&modul='.$modul); |
||
57 | } |
||
58 | |||
59 | if ($aktion == 'destroy') |
||
60 | { |
||
61 | db_query("UPDATE `".$WBConfig->getMySQLPrefix()."users` SET `fastlogin_secret` = '' WHERE `id` = '".$benutzer['id']."'"); |
||
62 | |||
63 | $aktion = 'delcookie'; |
||
64 | } |
||
65 | |||
66 | if ($aktion == 'delcookie') |
||
67 | { |
||
68 | wbUnsetCookie('wb_fastlogin_key'); |
||
69 | |||
70 | wb_redirect_now($_SERVER['PHP_SELF'].'?seite=main&modul='.$modul); |
||
71 | } |
||
72 | |||
73 | ?> |