07263d42b15467a44bdbeca02fb9edd568b97df9
bernd input-filtering

bernd authored 16 years ago

1) <?php
2) 
3) 
bernd * Passwörter mit cracklib p...

bernd authored 16 years ago

4) function strong_password($password)
5) {
6)   include("config.php");
7)   DEBUG("Öffne Wörterbuch: {$config['cracklib_dict']}");
8)   if (! ($dict = crack_opendict($config['cracklib_dict'])))
9)   {
10)     logger("inc/security.php", "cracklib", "could not open cracklib-dictionary »{$config['cracklib_dict']}«");
11)     system_failure("Kann Crack-Lib-Wörterbuch nicht öffnen: {$config['cracklib_dict']}");
12)   }
13)   // Führe eine Überprüfung des Passworts durch
14)   $check = crack_check($dict, $password);
15) 
16)   $message = crack_getlastmessage();
17)   crack_closedict($dict);
18) 
19)   if ($check === True)
20)   {
21)     DEBUG("Passwort ok");
22)     return true;
23)   }
24)   else
25)   {
26)     DEBUG("Passwort nicht ok: {$message}");
27)     return $message;
28)   }
29) }
30) 
31) 
bernd input-filtering

bernd authored 16 years ago

32) function filter_input_general( $input )
33) {
34)         return htmlspecialchars(iconv('UTF-8', 'UTF-8', $input), ENT_QUOTES, 'UTF-8');
35) }
36) 
37) 
38) function filter_input_username( $input )
39) {
40)         return ereg_replace("[^[:alnum:]\_\.\+\-]", "", $input );
41) }
42) 
bernd check auf hostname

bernd authored 16 years ago

43) function filter_input_hostname( $input )
44) {
45)         $input = strtolower($input);
46)         return ereg_replace("[^[:alnum:]äöü\.\-]", "", $input );
47) }
48) 
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

49) function filter_quotes( $input )
50) {
51)         return ereg_replace('["\'`]', '', $input );
52) }
53) 
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

54) function filter_shell( $input )
55) {
bernd shell-escaping braucht whit...

bernd authored 16 years ago

56)         return ereg_replace('[^-[:alnum:]\_\.\+ßäöüÄÖÜ/%§=]', '', $input );
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

57) }
bernd input-filtering

bernd authored 16 years ago

58) 
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

59) function check_path( $input )
60) {
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

61)   DEBUG("checking {$input} for valid path name");
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

62)   if ($input != filter_input_general($input))
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

63)   {
64)     DEBUG("HTML-Krams im Pfad");
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

65)     return False;
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

66)   }
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

67)   $components = explode("/", $input);
68)   foreach ($components AS $item)
69)   {
70)     if ($item == '..')
71)     {
bernd check auf hostname

bernd authored 16 years ago

72)       DEBUG("»..« im Pfad");
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

73)       return False;
74)     }
75)   }
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

76)   return (preg_match('/^[a-z0-9.@\/_-]*$/',$input) == 1);
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

77) }
78) 
79) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

80) function check_emailaddr( $input )
81) {
82)         return (preg_match("/^[a-z]+[a-z0-9]*[\.|\-|_]?[a-z0-9]+@([a-z0-9]*[\.|\-]?[a-z0-9]+){1,4}\.[a-z]{2,4}$/i", $input ) == 1);
83) }
84)