/** * @see generate_password_recover() generate a hask link for recover a password * @return boolean Always return true */ public function generate_password_recover() { /** * @var class hash_pass Class Hash_pass * @var class $DBsettings D.B settings */ $hash_sha512 = new hash_pass(); $DBsettings = (include $setting); //something do not work with $this->database[1] so we use $DBsettings[1] $hashed_link = $hash_sha512->hash($this->email_address, $hash_sha512->generateSalt()); // Update new link for reset password $sql = "UPDATE {$DBsettings['1']}.`user_account` SET `forget_password` = '{$hashed_link}' WHERE `user_account`.`email_address` = '{$this->email_address}'"; $reponse = $this->bdd->prepare($sql); $reponse->execute(); try { try { error_reporting(E_ALL); ini_set('display_errors', 1); require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/swiftmailer/lib/swift_required.php'; } catch (Exception $e) { echo 'Exception reçue : ' . $e->getMessage() . "\n"; } $this->message = 'You can reset your password by using this link :' . ' www.cloudiaproject.org/controllers/account/forget' . '_password.php?link=' . $hashed_link; $this->subject = "Cloudia : Reset your password"; $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")->setUsername('*****@*****.**')->setPassword('Pampa%Burger'); // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); // Create a message $message = Swift_Message::newInstance()->setSubject($this->subject)->setFrom(array('*****@*****.**' => 'ClouDIA\'s team'))->setTo(array('*****@*****.**', '*****@*****.**' => 'A name'))->setBody($this->message)->addPart('<q>TEXT DINDICATION</q>', 'text/html'); if ($mailer->send($message)) { echo "Sent\n"; } else { echo "Failed\n"; } } catch (Exception $e) { echo $e->getMessage() . '<br>'; echo '<pre>' . $e->getTraceAsString() . '</pre>'; } $email_sender = new email_sender($hashed_link, $this->email_address); echo "before send_password_reset()"; $email_sender->send_password_reset(); $reponse->closeCursor(); // End of Query return true; }
<!-- Author : Donavan Martin Team : CLouDIA WEB Country: Sherbrooke, Quebec, Canada Date : 1 juin 2015 --> <?php //include include "../../controllers/account/hash_pass.class.php"; // Hash Class $DBsettings = (include '../../server/DB_settings.php'); /**<D.B. settings */ $available = true; /**<Username avaible to input in D.B */ $hash_sha512 = new hash_pass(); /**<For hasching user's password */ try { // Connect to database $bdd = new PDO(sprintf('mysql:host=%s;dbname=%s;charset=utf8', $DBsettings[0], $DBsettings[1]), $DBsettings[2], $DBsettings[3]); } 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; }