Passed
Push — master ( 9424c8...428f38 )
by Anthony
03:16
created

Membre   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 208
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 7
Bugs 1 Features 0
Metric Value
wmc 31
c 7
b 1
f 0
lcom 1
cbo 3
dl 0
loc 208
rs 9.8

13 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 26 4
A getIdidentite() 0 3 1
A getNom() 0 3 1
A getPrenom() 0 3 1
A getPseudo() 0 3 1
A getMail() 0 3 1
A getImg() 0 3 1
A getMdp() 0 3 1
A getValide() 0 3 1
A getErreur() 0 3 1
B setPseudo() 0 28 5
B setMdp() 0 37 5
C testpassword() 0 43 8
1
<?php
2
	namespace core\auth;
3
4
5
	class Membre {
6
		protected $id_identite;
7
		protected $nom;
8
		protected $prenom;
9
		protected $mail;
10
		protected $pseudo;
11
		protected $img;
12
		protected $mdp;
13
		protected $valide;
14
		protected $erreur;
15
		
16
		private $debut_lien;
17
		
18
		//------------------------------ constructeur-----------------------------------
19
		//Récupérer en base de données les infos du membre
20
		public function __construct($id_identite = null) {
21
			$dbc = \core\App::getDb();
22
23
			$this->debut_lien = IMGROOT."profil/";
24
25
			if ($id_identite != null) {
26
				$query = $dbc->query("SELECT * FROM identite where ID_identite=$id_identite");
27
28
				foreach ($query as $obj) {
0 ignored issues
show
Bug introduced by
The expression $query of type array|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
29
					$this->id_identite = $obj->ID_identite;
30
					$this->nom = $obj->nom;
31
					$this->prenom = $obj->prenom;
32
					$this->mail = $obj->mail;
33
					$this->pseudo = $obj->pseudo;
34
					$this->mdp = $obj->mdp;
35
					$this->valide = $obj->valide;
36
37
					if ($obj->img_profil == "") {
38
						$this->img = $this->debut_lien."defaut.png";
39
					}
40
					else {
41
						$this->img = $obj->img_profil;
42
					}
43
				}
44
			}
45
		}
46
		//------------------------------ fin constructeur -----------------------------------
47
		
48
		
49
		
50
		//------------------------------ getter-----------------------------------
51
		public function getIdidentite() {
52
			return $this->id_identite;
53
		}
54
		public function getNom() {
55
			return $this->nom;
56
		}
57
		public function getPrenom() {
58
			return $this->prenom;
59
		}
60
		public function getPseudo() {
61
			return $this->pseudo;
62
		}
63
		public function getMail() {
64
			return $this->mail;
65
		}
66
		public function getImg() {
67
			return $this->img;
68
		}
69
		public function getMdp() {
70
			return $this->mdp;
71
		}
72
		public function getValide() {
73
			return $this->valide;
74
		}
75
		public function getErreur() {
76
			return $this->erreur;
77
		}
78
		//------------------------------ fin getter -----------------------------------
79
		
80
		
81
		
82
		//------------------------------ setter-----------------------------------
83
84
		/**
85
		 * @param string $new_pseudo
86
		 */
87
		public function setPseudo($new_pseudo) {
88
			$dbc = \core\App::getDb();
89
			
90
			//recherche si pseudo pas deja existant
91
			$pseudo_bdd = "";
92
			$query = $dbc->query("SELECT pseudo FROM identite WHERE pseudo=$new_pseudo");
93
			foreach ($query as $obj) {
0 ignored issues
show
Bug introduced by
The expression $query of type array|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
94
				$pseudo_bdd = $dbc->quote(htmlspecialchars($obj->pseudo));
95
			}
96
			
97
			//si pseudo trop court
98
			if (strlen($new_pseudo) < 5) {
99
				$err = "Votre pseudo est trop court";
100
				$this->erreur = $err;
101
			}
102
			else if (strlen($new_pseudo) > 15) {
103
				$err = "Votre pseudo est trop long";
104
				$this->erreur = $err;
105
			}
106
			else if ($new_pseudo == $pseudo_bdd) {
107
				$err = "Ce pseudo est déjà utilisé, veuillez en choisir un autre";
108
				$this->erreur = $err;
109
			}
110
			else {
111
				$dbc->query("UPDATE identite set pseudo=$new_pseudo WHERE ID_identite=".$_SESSION["idlogin".CLEF_SITE]);
112
				$this->pseudo = $new_pseudo;
113
			}
114
		}
115
116
		/**
117
		 * @param string $old_mdp
118
		 * @param string $new_mdp
119
		 * @param string $verif_new_mdp
120
		 */
121
		public function setMdp($old_mdp, $new_mdp, $verif_new_mdp) {
122
			$dbc = \core\App::getDb();
123
124
			$mdp = Encrypt::setDecryptMdp($this->mdp, $this->id_identite);
125
126
			
127
			//si mdp trop court
128
			if (md5($old_mdp) != $mdp) {
129
				$err = "Votre mot de passe est incorrect";
130
				$this->erreur = $err;
131
			}
132
			else {
133
				if ($new_mdp != $verif_new_mdp) {
134
					$err = "Vos mots de passe sont différents";
135
					$this->erreur = $err;
136
				}
137
				else {
138
					$testmdp = $this->testpassword($new_mdp);
139
					
140
					if (strlen($new_mdp) < 5) {
141
						$err = "Votre mot de passe est trop court";
142
						$this->erreur = $err;
143
					}
144
					else if ($testmdp < 40) {
145
						$err = "Votre mot de passe est trop simple";
146
						$this->erreur = $err;
147
					}
148
					else {
149
						$mdpok = Encrypt::setEncryptMdp($new_mdp, $this->id_identite);
150
						//le nouveau mdp est bon on update
151
						$dbc->query("UPDATE identite SET mdp='$mdpok' WHERE ID_identite=".$this->id_identite);
152
153
						$this->mdp = $mdpok;
154
					}
155
				}
156
			}
157
		}
158
		//------------------------------ fin setter -----------------------------------
159
160
161
		//-------------------------- FONCTIONS SPECIFIQUES ----------------------------------------------------------------------------//
162
		//-------------------------- FONCTIONS POUR TESTER SECURITE D'UN MDP ----------------------------------------------------------------------------//
163
		/**
164
		 * Fonction  qui permet de verifier la securite d'un mdp
165
		 * @param string $mdp
166
		 * @return integer
167
		 */
168
		private function testpassword($mdp) {
169
			$longueur = strlen($mdp);
170
			$point = 0;
171
			$point_min = 0;
172
			$point_maj = 0;
173
			$point_chiffre = 0;
174
			$point_caracteres = 0;
175
176
			for ($i = 0; $i < $longueur; $i++) {
177
				$lettre = $mdp[$i];
178
179
				if ($lettre >= 'a' && $lettre <= 'z') {
180
					$point = $point + 1;
181
					$point_min = 1;
182
				}
183
				else if ($lettre >= 'A' && $lettre <= 'Z') {
184
					$point = $point + 2;
185
					$point_maj = 2;
186
				}
187
				else if ($lettre >= '0' && $lettre <= '9') {
188
					$point = $point + 3;
189
					$point_chiffre = 3;
190
				}
191
				else {
192
					$point = $point + 5;
193
					$point_caracteres = 5;
194
				}
195
			}
196
197
			// Calcul du coefficient points/longueur
198
			$etape1 = $point / $longueur;
199
200
			// Calcul du coefficient de la diversite des types de caracteres...
201
			$etape2 = $point_min + $point_maj + $point_chiffre + $point_caracteres;
202
203
			// Multiplication du coefficient de diversite avec celui de la longueur
204
			$resultat = $etape1 * $etape2;
205
206
			// Multiplication du resultat par la longueur de la chaene
207
			$final = $resultat * $longueur;
208
209
			return $final;
210
		}
211
		//-------------------------- FIN FONCTIONS POUR TESTER SECURITE D'UN MDP ----------------------------------------------------------------------------//
212
	}