/** * @see update_password() update current password * @param $old_password Current password * @param $new_password New password * @return string Return error \\ Return True if changed */ public function update_password($old_password, $new_password) { $hash_sha512 = new hash_pass(); //something do not work with $this->database[1] so we use $DBsettings[1] $DBsettings = (include $setting); // Check if the old password is correct first! if ($this->verify_password($old_password)) { if ($old_password != $new_password) { $error = $this->verify_password_restriction($new_password); if ($error == false) { // Change Password $pass_hache = $hash_sha512->singleHash($new_password); if ($this->email_address != NULL) { $sql = "UPDATE {$DBsettings['1']}.`user_account` SET `password` = '{$pass_hache}' WHERE `user_account`.`email_address` = '{$this->email_address}'"; } else { if ($this->username != NULL) { $sql = "UPDATE {$DBsettings['1']}.`user_account` SET `password` = '{$pass_hache}' WHERE `user_account`.`email_address` = '{$this->username}'"; } else { return false; } } $reponse = $this->bdd->prepare($sql); $reponse->execute(); $reponse->closeCursor(); // End of Query return "true"; } return $error; } $error = "Current Password and New password are the same"; return $error; } return "Current password do not match"; }
} catch (Exception $e) { // Stop if errors die('Erreur : ' . $e->getMessage()); } //Get all e-mail and username $reponse = $bdd->query('SELECT username, email_address FROM user_account'); /**<Query reponse */ //Verify in table the e-mail or username already exists while ($donnees = $reponse->fetch()) { if ($_POST['Email'] == $donnees['email_address'] or $_POST['Username'] == $donnees['username']) { $available = false; } } //Verify the password if the account not founded if ($available) { // Haching password $pass_hache = $hash_sha512->singleHash($_POST['Password1']); // Insert new account $req = $bdd->prepare('INSERT INTO `test`.`user_account`(username, password, first_name, last_name, email_address, phone_number, subscribe_date, extension, active) VALUES(:pseudo, :pass, :f_name, :l_name, :email, :phone, CURDATE(), :ext, :active)'); $req->execute(array('pseudo' => $_POST['Username'], 'pass' => $pass_hache, 'f_name' => $_POST['FirstName'], 'l_name' => $_POST['LastName'], 'email' => $_POST['Email'], 'phone' => $_POST['TelephoneNumber'], 'ext' => "member", 'active' => 0)); $reponse->closeCursor(); // End of Query echo '<script>window.location = "../account/account_created.php";</script>'; } else { echo "E-mail alreday used, SORRY ! <br />"; } $reponse->closeCursor(); // End of Query ?>