Passed
Push — master ( f418e9...b58333 )
by Anthony
04:11
created

Membre::getIdidentite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
	namespace core\auth;
3
4
5
	use core\images\Resize;
6
7
	class Membre {
8
		protected $id_identite;
9
		protected $nom;
10
		protected $prenom;
11
		protected $mail;
12
		protected $pseudo;
13
		protected $img;
14
		protected $mdp;
15
		protected $valide;
16
		protected $erreur;
17
		
18
		private $debut_lien;
19
		
20
		//------------------------------ constructeur-----------------------------------
21
		//Récupérer en base de données les infos du membre
22
		public function __construct($id_identite=null){
23
			$dbc = \core\App::getDb();
24
25
			$this->debut_lien = IMGROOT."profil/";
26
27
			if ($id_identite != null) {
28
				$query = $dbc->query("SELECT * FROM identite where ID_identite=$id_identite");
29
30
				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...
31
					$this->id_identite = $obj->ID_identite;
32
					$this->nom = $obj->nom;
33
					$this->prenom = $obj->prenom;
34
					$this->mail = $obj->mail;
35
					$this->pseudo = $obj->pseudo;
36
					$this->mdp = $obj->mdp;
37
					$this->valide = $obj->valide;
38
39
					if ($obj->img_profil == "") {
40
						$this->img = $this->debut_lien."defaut.png";
41
					}
42
					else {
43
						$this->img = $obj->img_profil;
44
					}
45
				}
46
			}
47
		}
48
		//------------------------------ fin constructeur -----------------------------------
49
		
50
		
51
		
52
		//------------------------------ getter-----------------------------------
53
		public function getIdidentite() {
54
			return $this->id_identite;
55
		}
56
		public function getNom() {
57
			return $this->nom;
58
		}
59
		public function getPrenom() {
60
			return $this->prenom;
61
		}
62
		public function getPseudo() {
63
			return $this->pseudo;
64
		}
65
		public function getMail() {
66
			return $this->mail;
67
		}
68
		public function getImg() {
69
			return $this->img;
70
		}
71
		public function getMdp() {
72
			return $this->mdp;
73
		}
74
		public function getValide() {
75
			return $this->valide;
76
		}
77
		public function getErreur() {
78
			return $this->erreur;
79
		}
80
		//------------------------------ fin getter -----------------------------------
81
		
82
		
83
		
84
		//------------------------------ setter-----------------------------------
85
		/**
86
		 * @param null $id_identite
87
		 */
88
		public function setSupprimUser($id_identite=null) {
89
			$dbc = \core\App::getDb();
90
91
			if ($id_identite == null) {
92
				$id_identite = $this->id_identite;
93
			}
94
			
95
			//test si il y a deja une img
96
			$query = $dbc->query("SELECT img_profil FROM identite where ID_identite=$id_identite");
97
			$query->setFetchMode(PDO::FETCH_OBJ);
0 ignored issues
show
Bug introduced by
The method setFetchMode cannot be called on $query (of type array|null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
98
			$obj = $query->fetch();
0 ignored issues
show
Bug introduced by
The method fetch cannot be called on $query (of type array|null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
99
			$oldimg_profil = $obj->img_profil;
100
			if ($oldimg_profil != "") {
101
				$oldimg_profil = explode("/", $oldimg_profil);
102
				if(end($oldimg_profil) == "defaut.png") {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
103
					
104
				}
105
				else {
106
					unlink("../../images/profil/".end($oldimg_profil));
107
					
108
				}
109
			}
110
			
111
			$dbc->prepare("DELETE FROM identite WHERE ID_identite=".$id_identite);
112
		}
113
114
		/**
115
		 * @param string $new_pseudo
116
		 */
117
		public function setPseudo($new_pseudo) {
118
			$dbc = \core\App::getDb();
119
			
120
			//recherche si pseudo pas deja existant
121
			$query = $dbc->query("SELECT pseudo FROM identite WHERE pseudo=$new_pseudo");
122
			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...
123
				$pseudo_bdd = $dbc->quote(htmlspecialchars($obj->pseudo));
124
			}
125
			
126
			//si pseudo trop court
127
			if (strlen($new_pseudo) < 5) {
128
				$err = "Votre pseudo est trop court";
129
				$this->erreur = $err;
130
			}
131
			else if (strlen($new_pseudo) > 15) {
132
				$err = "Votre pseudo est trop long";
133
				$this->erreur = $err;
134
			}
135
			else if ($new_pseudo == $pseudo_bdd) {
0 ignored issues
show
Bug introduced by
The variable $pseudo_bdd does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
136
				$err = "Ce pseudo est déjà utilisé, veuillez en choisir un autre";
137
				$this->erreur = $err;
138
			}
139
			else {
140
				$dbc->query("UPDATE identite set pseudo=$new_pseudo WHERE ID_identite=".$_SESSION["idlogin".CLEF_SITE]);
141
				$this->pseudo = $new_pseudo;
142
			}
143
		}
144
145
		/**
146
		 * @param string $old_mdp
147
		 * @param string $new_mdp
148
		 * @param string $verif_new_mdp
149
		 */
150
		public function setMdp($old_mdp, $new_mdp, $verif_new_mdp) {
151
			$dbc = \core\App::getDb();
152
153
			$mdp = Encrypt::setDecryptMdp($this->mdp, $this->id_identite);
154
155
			
156
			//si mdp trop court
157
			if (md5($old_mdp) != $mdp) {
158
				$err = "Votre mot de passe est incorrect";
159
				$this->erreur = $err;
160
			}
161
			else {
162
				if ($new_mdp != $verif_new_mdp) {
163
					$err = "Vos mots de passe sont différents";
164
					$this->erreur = $err;
165
				}
166
				else {
167
					$testmdp = $this->testpassword($new_mdp);
168
					
169
					if (strlen($new_mdp) < 5) {
170
						$err = "Votre mot de passe est trop court";
171
						$this->erreur = $err;
172
					}
173
					else if ($testmdp < 40) {
174
						$err = "Votre mot de passe est trop simple";
175
						$this->erreur = $err;
176
					}
177
					else {
178
						$mdpok = Encrypt::setEncryptMdp($new_mdp, $this->id_identite);
179
						//le nouveau mdp est bon on update
180
						$dbc->query("UPDATE identite SET mdp='$mdpok' WHERE ID_identite=".$this->id_identite);
181
182
						$this->mdp = $mdpok;
183
					}
184
				}
185
			}
186
		}
187
		//------------------------------ fin setter -----------------------------------
188
189
190
		//-------------------------- FONCTIONS SPECIFIQUES ----------------------------------------------------------------------------//
191
		//-------------------------- FONCTIONS POUR TESTER SECURITE D'UN MDP ----------------------------------------------------------------------------//
192
		/**
193
		 * Fonction  qui permet de verifier la securite d'un mdp
194
		 * @param string $mdp
195
		 * @return integer
196
		 */
197
		function testpassword($mdp)	{
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
198
			$longueur = strlen($mdp);
199
			$point = 0;
200
201
			for ($i=0 ; $i<$longueur ; $i++) 	{
202
				$lettre = $mdp[$i];
203
204
				if ($lettre >= 'a' && $lettre <= 'z') {
205
					$point = $point + 1;
206
					$point_min = 1;
207
				}
208
				else if ($lettre >= 'A' && $lettre <= 'Z'){
209
					$point = $point + 2;
210
					$point_maj = 2;
211
				}
212
				else if ($lettre >= '0' && $lettre <= '9'){
213
					$point = $point + 3;
214
					$point_chiffre = 3;
215
				}
216
				else {
217
					$point = $point + 5;
218
					$point_caracteres = 5;
219
				}
220
			}
221
222
			// Calcul du coefficient points/longueur
223
			$etape1 = $point / $longueur;
224
225
			// Calcul du coefficient de la diversite des types de caracteres...
226
			$etape2 = $point_min + $point_maj + $point_chiffre + $point_caracteres;
0 ignored issues
show
Bug introduced by
The variable $point_min does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $point_maj does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $point_chiffre does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $point_caracteres does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
227
228
			// Multiplication du coefficient de diversite avec celui de la longueur
229
			$resultat = $etape1 * $etape2;
230
231
			// Multiplication du resultat par la longueur de la chaene
232
			$final = $resultat * $longueur;
233
234
			return $final;
235
		}
236
		//-------------------------- FIN FONCTIONS POUR TESTER SECURITE D'UN MDP ----------------------------------------------------------------------------//
237
	}