Passed
Push — master ( b72488...021c63 )
by Anthony
03:14
created

Membre::testpassword()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
c 5
b 1
f 0
dl 0
loc 9
rs 9.6666
cc 3
eloc 5
nc 3
nop 1
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
				if ((is_array($query)) && (count($query) > 0)) {
29
					foreach ($query as $obj) {
30
						$this->id_identite = $obj->ID_identite;
31
						$this->nom = $obj->nom;
32
						$this->prenom = $obj->prenom;
33
						$this->mail = $obj->mail;
34
						$this->pseudo = $obj->pseudo;
35
						$this->mdp = $obj->mdp;
36
						$this->valide = $obj->valide;
37
						$this->img = $obj->img_profil;
38
					}
39
				}
40
			}
41
		}
42
		//------------------------------ fin constructeur -----------------------------------
43
		
44
		
45
		
46
		//------------------------------ getter-----------------------------------
47
		public function getIdidentite() {
48
			return $this->id_identite;
49
		}
50
		public function getNom() {
51
			return $this->nom;
52
		}
53
		public function getPrenom() {
54
			return $this->prenom;
55
		}
56
		public function getPseudo() {
57
			return $this->pseudo;
58
		}
59
		public function getMail() {
60
			return $this->mail;
61
		}
62
		public function getImg() {
63
			return $this->img;
64
		}
65
		public function getMdp() {
66
			return $this->mdp;
67
		}
68
		public function getValide() {
69
			return $this->valide;
70
		}
71
		public function getErreur() {
72
			return $this->erreur;
73
		}
74
		//------------------------------ fin getter -----------------------------------
75
		
76
		
77
		
78
		//------------------------------ setter-----------------------------------
79
80
		/**
81
		 * @param string $new_pseudo
82
		 */
83
		public function setPseudo($new_pseudo) {
84
			$dbc = \core\App::getDb();
85
			
86
			//si pseudo trop court
87
			if ((strlen($new_pseudo) < 5) || (strlen($new_pseudo) > 15)) {
88
				$err = "Votre pseudo doit être entre 5 et 15 caractères";
89
				$this->erreur = $err;
90
			}
91
			else if ($dbc->rechercherEgalite("identite", "pseudo", $new_pseudo) == false) {
92
				$err = "Ce pseudo est déjà utilisé, veuillez en choisir un autre";
93
				$this->erreur = $err;
94
			}
95
			else {
96
				$dbc->query("UPDATE identite set pseudo=$new_pseudo WHERE ID_identite=".$_SESSION["idlogin".CLEF_SITE]);
97
				$this->pseudo = $new_pseudo;
98
			}
99
		}
100
101
		/**
102
		 * @param string $old_mdp
103
		 * @param string $new_mdp
104
		 * @param string $verif_new_mdp
105
		 */
106
		public function setMdp($old_mdp, $new_mdp, $verif_new_mdp) {
107
			$dbc = \core\App::getDb();
108
109
			$mdp = Encrypt::setDecryptMdp($this->mdp, $this->id_identite);
110
111
			//si mdp trop court
112
			if (md5($old_mdp) != $mdp) {
113
				$err = "Votre mot de passe est incorrect";
114
				$this->erreur = $err;
115
			}
116
			else if ($new_mdp != $verif_new_mdp) {
117
				$err = "Vos mots de passe sont différents";
118
				$this->erreur = $err;
119
			}
120
			else if ($this->testpassword($new_mdp) == false) {
121
				$err = "Votre mot de passe est trop simple, il doit contenir 5 caractères et au moins un chiffre";
122
				$this->erreur = $err;
123
			}
124
			else {
125
				$mdpok = Encrypt::setEncryptMdp($new_mdp, $this->id_identite);
126
				//le nouveau mdp est bon on update
127
				$dbc->query("UPDATE identite SET mdp='$mdpok' WHERE ID_identite=".$this->id_identite);
128
129
				$this->mdp = $mdpok;
130
			}
131
		}
132
		//------------------------------ fin setter -----------------------------------
133
134
135
		//-------------------------- FONCTIONS SPECIFIQUES ----------------------------------------------------------------------------//
136
		//-------------------------- FONCTIONS POUR TESTER SECURITE D'UN MDP ----------------------------------------------------------------------------//
137
		/**
138
		 * Fonction  qui permet de verifier la securite d'un mdp
139
		 * @param string $mdp
140
		 * @return integer
141
		 */
142
		private function testpassword($mdp) {
143
			if (strlen($mdp) < 5) {
144
				return false;
145
			}
146
147
			if (!preg_match("#[0-9]+#", $mdp)) {
148
				return false;
149
			}
150
		}
151
		//-------------------------- FIN FONCTIONS POUR TESTER SECURITE D'UN MDP ----------------------------------------------------------------------------//
152
	}