CS代考 Computer Science 571 2nd Exam Prof. , December 3, 2013, 12:30pm – 1:45pm

Computer Science 571 2nd Exam Prof. , December 3, 2013, 12:30pm – 1:45pm
1. This is a closed book exam.
2. Please answer all questions on the test
 jQuery [20 pts]

Copyright By PowCoder代写 加微信 powcoder

 Javascript + Ajax [20 pts]
 PHP + Regular Expressions [15 pts]  Cookies and Privacy [15 pts]
 XML Schemas [15 pts]
 Web Security [15 pts]
jQuery [20 pts]
1. [10 pts]
Student ID Number:
Below is a web page with three occurrences of the sentence “This is a paragraph”. The first sentence has a red background, the second has a green background and the third has a blue background. The button “Set background-color of p” resets the background color of all three sentences to yellow background. Below is the code that accomplishes this. Fill in the missing jQuery pieces.
Initial screen all the same color
This study source was downloaded by 100000827663389 from CourseHero.com on 10-04-2022 23:00:16 GMT -05:00
https://www.coursehero.com/file/11496937/cs571-13fa-final-horowitz-s2V2-answers/



$(document).ready(function(){
$(“button”).click(function(){ $(“p”).css(“background-color”,”yellow”);

This is a heading

This is a paragraph.

This is a paragraph.

This is a paragraph.

This is a paragraph.


2. [10 pts]
Below are two screenshots. The first has a button and the second shows what happens once the button is clicked. The button issues a POST request and returns the result in an alert box. Below that is the code that implements the button, with some of the jQuery code removed. Fill in the missing jQuery code.
Initial screen After Button is Clicked


This study source was downloaded by 100000827663389 from CourseHero.com on 10-04-2022 23:00:16 GMT -05:00
https://www.coursehero.com/file/11496937/cs571-13fa-final-horowitz-s2V2-answers/

$(document).ready(function(){
$(“button”).click(function(){
$.post(“script.php”,
city:”Duckburg”
function(data,status){
alert(“Data: ” + data + “\nStatus: ” + status);

JavaScript + Ajax [20 pts]
3. [10 pts]
JSONscriptRequest is a simple class for making HTTP requests using dynamically generated script tags and JSON. Below is a sample that uses the Yahoo service for returning Latitude and Longitude given a zip code. Fill in the missing code.

function callbackfunc(jsonData) {
alert(‘Latitude = ‘ + jsonData.ResultSet.Result[0].Latitude +
‘ Longitude = ‘ + jsonData.ResultSet.Result[0].Longitude); aObj.removeScriptTag();
request = ‘http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&
output=json&callback=callbackfunc&location=78704’; aObj = new JSONscriptRequest(request);
aObj.buildScriptTag();
aObj.addScriptTag();
function JSONscriptRequest(fullUrl) {
this.fullUrl = fullUrl;
this.noCacheIE = ‘&noCacheIE=’ + (new Date()).getTime(); this.headLoc = document.getElementsByTagName(“head”).item(0); this.scriptId = ‘JscriptId’ + JSONscriptRequest.scriptCounter++;
JSONscriptRequest.prototype.buildScriptTag = function () {
this.scriptObj = document.createElement(“script”); this.scriptObj.setAttribute(“type”, “text/javascript”); this.scriptObj.setAttribute(“charset”, “utf-8”); this.scriptObj.setAttribute(“src”, this.fullUrl + this.noCacheIE);
This study source was downloaded by 100000827663389 from CourseHero.com on 10-04-2022 23:00:16 GMT -05:00
https://www.coursehero.com/file/11496937/cs571-13fa-final-horowitz-s2V2-answers/

this.scriptObj.setAttribute(“id”, this.scriptId); }
4. [10 pts]
Below are two screenshots, one representing an initial page and a second showing what occurs after the “Request data” button is clicked. Below that is the code that produces the effect. Supply the missing code.
Initial Screen After the button is clicked

AJAX


This study source was downloaded by 100000827663389 from CourseHero.com on 10-04-2022 23:00:16 GMT -05:00
https://www.coursehero.com/file/11496937/cs571-13fa-final-horowitz-s2V2-answers/

PHP and Regular Expressions [15 pts]
5. [5 pts]
Determine what the following PHP code outputs:
$str = ‘foobar: 2008’;
preg_match(‘/(?P\w+): (?P\d+)/’, $str, $matches); print_r($matches);
[0] => foobar: 2008
[name] => foobar
[1] => foobar
[digit] => 2008
[2] => 2008 )
6. [5 pts]
Below is a PHP program; once you understand what the program does supply appropriate output messages
$regexp = 9_]+)*[.][A-z]{2,4}$/”;
if (preg_match($regexp, $string)) {
echo “Email address is valid.”;
echo “Email address is not valid.”;
7. [5 pts]
Determine what the following PHP function returns:
function doit($x)
{return preg_match(‘|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?
a. What is the result when the input $x is:
http://www.usc.edu:a1234/index.html
b. What is the result when the input $x is:
This study source was downloaded by 100000827663389 from CourseHero.com on 10-04-2022 23:00:16 GMT -05:00
(/.*)?$|i’, $x);
https://www.coursehero.com/file/11496937/cs571-13fa-final-horowitz-s2V2-answers/

https://www.google.com
c. In one sentence explain what the function does and what you would use it for?
b. true (need to check!!) c. Validates a URL
Cookies and Privacy [15 pts]
User Logon

User Login

Username:
Password:
Remember Me:


Below is the source code for login.php. Fill in the missing code and answer the questions below.
/* These are our valid username and passwords */
This study source was downloaded by 100000827663389 from CourseHero.com on 10-04-2022 23:00:16 GMT -05:00
https://www.coursehero.com/file/11496937/cs571-13fa-final-horowitz-s2V2-answers/

$user = ‘jonny4’;
$pass = ‘delafoo’;
if (isset($_POST[‘username’]) && isset($_POST[‘password’)) {
if (($_POST[‘username’] == $user) && ($_POST[‘password’] == $pass)) {
if (isset($_POST[‘rememberme’])) {
setcookie(‘username’, $_POST[‘username’], time()+60*60*24*365,
‘/account’, ‘www.example.com’);
setcookie(‘password’, md5($_POST[‘password’]), time()+60*60*24*365,
‘/account’, ‘www.example.com’);
setcookie(‘username’, $_POST[‘username’], false, ‘/account’, ‘www.example.com’);
setcookie(‘password’, md5($_POST[‘password’]), false, ‘/account’, ‘www.example.com’);
header(‘Location: index.php’);
echo ‘Username/Password Invalid’;
8. [5 pts]
If rememberme is chosen, how long will the cookie last?
Answer: 1 year
9. [5 pts]
If rememberme is NOT chosen, how long will the cookie last?
Answer: when the browser closes
10. [5 pts]
What is md5?
Answer: a function which produces a hash value for the password
XML Schemas [15 pts]
Below is an XML schema that describes a Bookstore. Answer the questions below.

















11. [5 pts]
a. what is the file suffix of this file?
Answer: xsd
12. [5 pts]
b. what is the name of the default namespace?
Answer: http://www.books.org
13. [5 pts]
c. What is the name of the data type defined above that can be exported to other Schema files?
Answer: Book, Title, Author, Date, ISBN, Publisher
Web Security [15 pts]
Define the following terms:
14. [5 pts]
This study source was downloaded by 100000827663389 from CourseHero.com on 10-04-2022 23:00:16 GMT -05:00
https://www.coursehero.com/file/11496937/cs571-13fa-final-horowitz-s2V2-answers/

Powered by TCPDF (www.tcpdf.org)
Brute force attack:
Answer: Brute Force attack is an automated process of trial and error used to guess a person’s username, password, session ids, credit-card, cryptographic key or anything that is unique to the user and authenticates him
15. [5 pts]
Cross-site scripting (XSS)
Answer: Cross-site scripting (XSS) enables attackers to inject client-side scripts into Web pages viewed by other users. A cross-site scripting vulnerability may be used by attackers to bypass access controls such as the same origin policy.
16. [5 pts]
Injection Attack
Answer: Injection Attacks occurs when an application does not properly validate user supplied input and then includes that input blindly in further processing.
This study source was downloaded by 100000827663389 from CourseHero.com on 10-04-2022 23:00:16 GMT -05:00
https://www.coursehero.com/file/11496937/cs571-13fa-final-horowitz-s2V2-answers/

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com