Web Technologies II - Midterm Exam
You may use as an aid the following resources: Any source code
Write your name on this exam sheet and write your answers on the answer
- (2 pts each) Write the appropriate Linux / Mercurial command to accomplish
each of the following tasks:
- list the files in the Web2/hw04 folder
- view the last several lines of the PHP error log
- use hg or git to view a list of changes since the last commit
- use hg or git to record a set of changes that fixed a login system bug
- (3 pts) What the difference between sanitizing and validation?
- (2 pts) Does bcrypt allow the use of salt values?
- (4 pts) Contrast client-side validation with server-side validation.
- (4 pts) Compare and contrast session-variables and cookies.
- (4 pts) In the context of a password management system, what is ``salt''
and how does it help secure passwords?
- Answers these questions about XSS attack:
- (3 pts) Explain (give names of commands if appropriate) how to prevent
a successful XSS attack.
- (3 pts) Suppose a form contains the following radio button group:
<input type="radio" name="favoritechipmonk" value="alvin" checked="checked" />
<input type="radio" name="favoritechipmonk" value="simon" />
<input type="radio" name="favoritechipmonk" value="theodore" />
Further suppose the landing page saves the posted value to the database.
If the value stored to the database is later displayed on a web page
is there any need to be concerned about an XSS attack? Explain.
- Suppose a PostgreSQL database resides on the same host as the web
server and is named gametracker (also the name of the database
user/owner) with a password of mysecret is used to store username,
password, and salt entries into a table named users (found in the
fun schema) which has the following structure:
CREATE TABLE users (
Further suppose that this database has been used successfully for some
time but that the site administrator wants to add a feature to the site
which allows a user to modify their password. In preparation for this
feature the following form has been created:
<form method="post" action="modifyPassword.php">
Username: <input type="text" name="uname" /> <br/>
Old Password: <input type="password" name="oldpw" /> <br/>
New Password: <input type="password" name="newpw" /> <br/>
New Password Again: <input type="password" name="newpwagain" /> <br/>
Write modifyPassword.php so that it accomplishes the following tasks:
- (4 pts) Connect to the database and give an error message if
unable to connect. Also, set the schema search path to fun.
- (4 pts) Sanitize the form data to prevent SQL injection
- (4 pts) Search in the database for the username specified in the
form. If no such user exists indicate so with an appropriate error
messages. (SQL to find entry with username of 'fred':
SELECT * FROM users WHERE username='fred')
- (6 pts) Verify that the old password matches what was stored in
the database. You should assume that the stored password is found by
concatenating the entered password with the stored salt value and then
applying the PHP sha1() function to the result (e.g.,
$encryptedval= sha1($val);). If the match fails give an
appropriate error message.
- (2 pts) Verify that the new passwords match one another. Give
an error message if not.
- (4 pts) Store the new password (concatenated with the stored
salt value followed by application of sha1()). (SQL to store
password for username 'fred':
UPDATE users SET password='newSaltedEncryptedPassword' WHERE username='fred')