WebFund 2013F: Assignment 2: Difference between revisions

From Soma-notes
Line 28: Line 28:
===Part B===
===Part B===


For the following, run <tt>node puzzle.js</tt>, listed below and included [http:// here].  At the <tt>puzzle></tt> prompt, what are the value(s) of the following expressions? (1 point each)
For the following, run <tt>node puzzle.js</tt>, listed below and included [http://homeostasis.scs.carleton.ca/~soma/webfund-2013f/puzzle.js here].  At the <tt>puzzle></tt> prompt, what are the value(s) of the following expressions? (1 point each)


(Assume that the expressions are entered in to the interpreter ''as ordered''.  In other words, the earlier expressions may influence the later ones.  If you get an error, report the kind of error, e.g. "reference error" or "type error".)
(Assume that the expressions are entered in to the interpreter ''as ordered''.  In other words, the earlier expressions may influence the later ones.  If you get an error, report the kind of error, e.g. "reference error" or "type error".)

Revision as of 20:08, 5 October 2013

This assignment is not yet finalized

Please submit your answers as a single text or PDF file uploaded to CULearn with "COMP 2406 Assignment 2", your name, student number, and the date as the first four lines of the file. No other formats will be accepted. Submitting in another format may result in your assignment not being graded and you receiving no marks for this assignment.

This assignment has 40 points.

Questions

Part A

The following questions are in reference to the session-demo sample node application covered in Tutorial 5.

  1. (2 points) What happens if you remove the line requiring the http module? The path module?
  2. (2 points) What is the secret used to help prevent attackers from creating their own fake session identifiers?
  3. (2 points) How can I change the port node listens on without changing the code?
  4. (2 points) The user "User" logs in to the application in two web browsers, A and B, simultaneously. "User" then logs out of browser A. After reloading /users in browser B, how many users are shown as being logged in? (Assume no other users.)
  5. (2 points) Does this application use client-side JavaScript? Explain briefly.
  6. (5 points) Modify the code so that it keeps track of how many times an individual user is logged in.
  7. (10 points) Modify the code so that sessions are authenticated. Specifically:
    • add a "Password" field and a "Register" button to /
    • When the register button is pressed:
      • If the user has not registered, store their username and password, return to /.
      • If the user has registered, generate an error at the top of / similar to that when accessing /users without being logged in. The error should be "Error: User has already registered."
    • When the login button is pressed:
      • If the user enters the correct password let them proceed to /users as before.
      • If the user enters an incorrect password or a username that isn't registered, return an error on / saying "Error: incorrect username/password". (Do not differentiate between an unregistered user and a registered user with an incorrect password.)

Part B

For the following, run node puzzle.js, listed below and included here. At the puzzle> prompt, what are the value(s) of the following expressions? (1 point each)

(Assume that the expressions are entered in to the interpreter as ordered. In other words, the earlier expressions may influence the later ones. If you get an error, report the kind of error, e.g. "reference error" or "type error".)

Note: You will be expected to answer similar questions on the midterm without the aid of a computer. So, you may want to try writing down your answers before running any code.

  1. p
  2. q
  3. y
  4. f = q
  5. f("Anil")
  6. f.g("Anil")
  7. f.h("Anil")
  8. f.g("Annie")
  9. f.j("y = \"boing\"")
  10. y
  11. f.j("x = \"goodbye \"")
  12. f.g("Michael")
  13. f.h("I recognize you!"); f.g("Michael");
  14. q.j("s.m = function(n,m,q) {x = n; a = m; b = q;}"); q.m("this", "is", "weird"); q.g("Anil");
  15. f.g("Anil");

Code

puzzle.js

var repl = require("repl");

y = "Yo";

var f = function(a) {
    var x = "hello ";
    var s = {};

    s.g = function(b) {
	return x + b + ", " + a;
    }

    s.h = function(c) {
	return a = c;
    }

    s.j = function(x) {
	return eval(x);
    }

    return s;
}

var p = f("do I know you?");

repl.start({
    prompt: "puzzle> ",
    useGlobal: true
    }).context.q = p;