public function generatePassword($password = '') { if (!$this->id) { return "Non è stato possibile trovare l'id dello studente, contattare il fornitore!"; } $tabella = "password"; //Controllo se esiste già una password per l'utente $sql = "SELECT * FROM {$tabella} WHERE id_studente ='{$this->id}'"; $auth = $this->connector->query($sql); if (mysql_num_rows($auth) > 0) { $res = $this->connector->getObjectResult($auth); } $pwdGen = new PasswordGenerator(); if ($password == "") { $password = $pwdGen->createPassword(); } else { $pwd = trim(filter_var($password, FILTER_SANITIZE_STRING)); } if ($res) { $valori = array(sha1($password)); $campi = array("password"); $campi_com = array("id_studente"); $valori_com = array($this->id); $auth = $this->connector->update($tabella, $campi, $valori, $campi_com, $valori_com); if (!$pwdGen->sendPassword($password, $this)) { return "Errore durante l'invio della password"; } } else { $valori = array($this->id, sha1($password)); $campi = array("id_studente", "password"); $auth = $this->connector->insert($tabella, $campi, $valori); } if (mysql_errno() > 0) { return "Errore interno numero: " . mysql_errno() . " " . mysql_error(); } }