function saveUsersEmail($emailUser, $newEmail) { $passwordUpdateSql = generatePasswordUpdateSql($emailUser, $newEmail); // connect to db $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); // check if username is unique $result = mysql_query($passwordUpdateSql, $dbLink); if (!$result) { echo $passwordUpdateSql; throw new Exception('Failed to update password'); } }
function reset_password($email) { // set password for username to a random value // return the new password or false on failure // get a random dictionary word b/w 6 and 13 chars in length $new_password = get_random_word(6, 13); if ($new_password == false) { throw new Exception('Could not generate new password.'); } // add a number between 0 and 999 to it // to make it a slightly better password $rand_number = rand(0, 999); $new_password .= $rand_number; $sql = generatePasswordUpdateSql($email, $new_password); // set user's password to this in database or return false $conn = db_connect(); $result = $conn->query($sql); if (!$result) { throw new Exception('Could not change password.'); // not changed } else { return $new_password; // changed successfully } }