Browse code

replace cracklib with zxcvbn

Hanno Böck authored on 21/10/2016 19:21:05
Showing 1 changed files
... ...
@@ -15,49 +15,19 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
15 15
 */
16 16
 
17 17
 require_once('inc/error.php');
18
+require_once('vendor/autoload.php');
18 19
 
19 20
 
20
-function strong_password($password)
21
+function strong_password($password, $user = array())
21 22
 {
22
-  if ($password == '' || strlen($password) < 4) {
23
-    DEBUG("Passwort zu kurz!");
24
-    return "Passwort ist zu kurz!";
25
-  }
23
+  $passwordchecker = new ZxcvbnPhp\Zxcvbn();
24
+  $strength = $passwordchecker->passwordStrength($password, $user);
26 25
 
27
-  if (! function_exists("crack_opendict"))
28
-  {
29
-    DEBUG("cracklib not available!");
30
-    return true;
31
-  }
32
-  if (config('use_cracklib') === NULL or config('use_cracklib') === false) {
33
-    DEBUG('Cracklib deaktiviert');
34
-    return true;
35
-  }
36
-  DEBUG("Öffne Wörterbuch: ".config('cracklib_dict'));
37
-  if (! ($dict = crack_opendict(config('cracklib_dict'))))
38
-  {
39
-    logger(LOG_ERR, "inc/security", "cracklib", "could not open cracklib-dictionary »".config('cracklib_dict')."«");
40
-    #system_failure("Kann Crack-Lib-Wörterbuch nicht öffnen: ".config('cracklib_dict'));
41
-    DEBUG('cracklib tut nicht, dann wird das PW akzeptiert');
42
-    warning('Das Passwort konnte aufgrund eines internen Fehlers nicht auf die Passwortstärke geprüft werden.');
43
-    return true;
26
+  if ($strength['score'] < 2) {
27
+    return "Das Passwort ist zu einfach!";
44 28
   }
45
-  // Führe eine Überprüfung des Passworts durch
46
-  $check = crack_check($dict, $password);
47 29
 
48
-  $message = crack_getlastmessage();
49
-  crack_closedict($dict);
50
-
51
-  if ($check === True)
52
-  {
53
-    DEBUG("Passwort ok");
54
-    return true;
55
-  }
56
-  else
57
-  {
58
-    DEBUG("Passwort nicht ok: {$message}");
59
-    return $message;
60
-  }
30
+  return true;
61 31
 }
62 32
 
63 33