Cookie use: storing login details

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Cookie use: storing login details

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A website saves a login cookie after you sign in. What does this let you do?
A Skip the login step on any website in the world
B Move between pages without typing your username and password again
2. Which statement about a login cookie is correct?
A It speeds up your internet connection
B It stores your login status so the site knows you are signed in
3. You stay logged in while you browse a shop's pages during one visit. What is most likely being used?
A A cookie holding your login status
B A new username and password typed on each page
4. You tick 'Remember me' when you log in. What does the website do?
A Saves a cookie so you can be recognised on a later visit
B Deletes the cookie as soon as you close the browser
5. You are using a shared school computer. What is the safest choice after you finish using your account?
A Log out so the login cookie no longer keeps you signed in
B Just close the tab and leave the account logged in

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Set-Cookie: loggedIn=true AloggedIn=true
2Set-Cookie: remember=yes; Max-Age=2592000 BThe login cookie may still be stored, so the next user could still be logged in as you.
3A cookie stores a login status so the user stays logged in while moving between pages during a visit CA remember me cookie that lasts 30 days, so the user stays logged in on future visits.
4Logging out on a shared computer deletes the login cookie so the next person cannot use your account DThe server tells the browser to store a login status cookie so the user stays logged in on later pages.
5Tick 'Remember me' on a school library computer EloggedIn=; Max-Age=0
6Close the browser without clicking Log out on a shared PC FOn a shared computer, a remember me cookie stays saved in the browser, so the next person could open your account.

Definitions

login cookie

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF loginCookieExists ____ DISPLAY "Welcome back" ENDIF
2.
IF rememberMe = TRUE THEN cookieType ← "__________" ENDIF
3.
IF userClicksLogout THEN ______ loginCookie ENDIF
4.
IF loginCookieFound = _____ THEN DISPLAY loginForm ENDIF
5.
IF sharedComputer = TRUE THEN cookieType ← "_______" ENDIF

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A INPUT username, password
B IF checkLogin() = TRUE THEN
C SAVE cookie loggedIn = FALSE
D ENDIF
Question 2
A ON PAGE LOAD
B READ cookie loggedIn
C IF loggedIn = FALSE THEN
D SHOW account page
E ELSE SHOW login form
F ENDIF
Question 3
A INPUT rememberMe
B IF rememberMe = TRUE THEN
C SET cookie type session
D ENDIF
Question 4
A IF user clicks LOGOUT THEN
B KEEP cookie loggedIn
C SHOW login form
D ENDIF
Question 5
A INPUT rememberMe
B IF rememberMe = FALSE THEN
C SAVE cookie loggedIn = TRUE
D SET cookie type persistent
E ENDIF

Answer Key

Cookie use: storing login details
Section A: Quick Questions
Q1
B — Move between pages without typing your username and password again
Q2
B — It stores your login status so the site knows you are signed in
Q3
A — A cookie holding your login status
Q4
A — Saves a cookie so you can be recognised on a later visit
Q5
A — Log out so the login cookie no longer keeps you signed in
Section B: Match the Pairs
Q1
Set-Cookie: loggedIn=true → The server tells the browser to store a login status cookie so the user stays logged in on later pages.
Q2
Set-Cookie: remember=yes; Max-Age=2592000 → A remember me cookie that lasts 30 days, so the user stays logged in on future visits.
Q3
A cookie stores a login status so the user stays logged in while moving between pages during a visit → loggedIn=true
Q4
Logging out on a shared computer deletes the login cookie so the next person cannot use your account → loggedIn=; Max-Age=0
Q5
Tick 'Remember me' on a school library computer → On a shared computer, a remember me cookie stays saved in the browser, so the next person could open your account.
Q6
Close the browser without clicking Log out on a shared PC → The login cookie may still be stored, so the next user could still be logged in as you.
Section C: Definitions
Q1
login cookie — A small file a website saves in your browser to remember you are logged in, so you do not have to type your username and password on every page.
Section D: Fill in the Blanks
Q1
IF loginCookieExists THEN DISPLAY "Welcome back" ENDIF
Q2
IF rememberMe = TRUE THEN cookieType ← "persistent" ENDIF
Q3
IF userClicksLogout THEN DELETE loginCookie ENDIF
Q4
IF loginCookieFound = FALSE THEN DISPLAY loginForm ENDIF
Q5
IF sharedComputer = TRUE THEN cookieType ← "session" ENDIF
Section E: Spot the Error
Q1
C — After a successful login the login cookie must record that the user IS logged in, so it should be set to TRUE. FALSE would make the site ask for the password again.
Q2
C — The account page should only be shown when the cookie says the user is logged in. The test must be loggedIn = TRUE.
Q3
C — A Remember me option needs a persistent cookie, which is stored after the browser closes. A session cookie would be deleted and the user would have to log in again.
Q4
B — On logout the login cookie must be deleted. If it is kept, the next person on a shared computer could open the account without a password.
Q5
D — If the user does not choose Remember me (for example on a shared computer), a session cookie should be used so it is deleted when the browser closes. It should not be persistent.