1: <?php
2:
3: /**
4: * Pry Framework
5: *
6: * LICENSE
7: *
8: * This source file is subject to the new BSD license that is bundled
9: * with this package in the file LICENSE.txt.
10: *
11: */
12: namespace Pry\Auth;
13: /**
14: * Outils utiles pour la gestion d'authentification
15: * @category Pry
16: * @package Auth
17: * @version 1.0.0
18: * @author Olivier ROGER <oroger.fr>
19: *
20: *
21: */
22: class Util
23: {
24:
25: /**
26: * Calcul la complexité d'un mot de passe
27: * Basé sur système d'ajout et suppression de point :
28: *
29: * minuscule = +(longeur-nbMinuscule)*nbMinuscule
30: * majuscule = +((longeur-nbMajus)*nbMajus)+3
31: * chiffre = +nbChiffre*4
32: * Autre = +nbAutre*8
33: *
34: * Retrait de point :
35: *
36: * - nbMinusculeConsecutive*2
37: * - nbMajConsecutive*2
38: * - nbChiffreConsec*2
39: * - nbAutreCharConsec
40: * - nbCharIdentique*3
41: *
42: * On peut juger les mdp comme suit 0-33 : mauvais; 33-66 : moyen; 66-100 : bon; 100+ : Excellent
43: *
44: * @param string $pass Mot de passe
45: * @return int
46: */
47: public static function passwordComplexity($pass)
48: {
49:
50: $longeur = mb_strlen($pass);
51: $numMin = 0;
52: $numMaj = 0;
53: $numChiffre = 0;
54: $numOther = 0;
55: $consecMinLetter = 0;
56: $consecMajLetter = 0;
57: $consecNum = 0;
58: $consecChar = 0;
59: $sameChar = 0;
60:
61: if ($longeur > 2)
62: {
63: for ($i = 0; $i < $longeur; $i++) {
64: if ($pass[$i] >= 'a' && $pass[$i] <= 'z')
65: {
66: $numMin++;
67: if ($i > 0 && ($pass[$i - 1] >= 'a' && $pass[$i - 1] <= 'z'))
68: $consecMinLetter++;
69: }
70: elseif ($pass[$i] >= 'A' && $pass[$i] <= 'Z')
71: {
72: $numMaj++;
73: if ($i > 0 && ($pass[$i - 1] >= 'A' && $pass[$i - 1] <= 'Z'))
74: $consecMajLetter++;
75: }
76: elseif ($pass[$i] >= 0 && $pass[$i] <= 9)
77: {
78: $numChiffre++;
79: if ($i > 0 && ($pass[$i - 1] >= 0 && $pass[$i - 1] <= 9))
80: $consecNum++;
81: }
82: else
83: {
84: $numOther++;
85: if ($i > 0 && !preg_match('/^([a-zA-Z0-9]+)$/', $pass[$i - 1]))
86: $consecChar++;
87: }
88:
89: if ($i > 0 && $pass[$i] == $pass[$i - 1])
90: $sameChar++;
91: }
92: $positiveScore = ($longeur * 2) + (($longeur - $numMin) * $numMin) + ((($longeur - $numMaj) * $numMaj) + 3) +
93: ($numChiffre * 4) + ($numOther * 8);
94: $score = $positiveScore - (($consecMinLetter * 2) + ($consecMajLetter * 2) + ($consecNum * 2) + $consecChar +
95: ($sameChar * 3));
96: return $score;
97: }
98: else
99: {
100: return 0;
101: }
102: }
103: }
104:
105: ?>