0% found this document useful (0 votes)
39 views2 pages

T2 Homework 2

Uploaded by

arushi.agupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

T2 Homework 2

Uploaded by

arushi.agupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Homework 2 Defensive design

Unit 8 Logic and languages

Name:............................................................................. Class:................... Mark:................

Look at the following program:


function validUsername(userName)
valid = True
if len(userName) > 10 or len(userName) < 5
valid = False
endif
return valid

uName = input("Enter your username: ")

if not validUsername(uName)
print("That isn't a valid username")
endif

(a) Explain what input validation is occurring in the program.


Checking if the username length is less than 10 and greater than 5- which are the boundaries
and if not then invalidating the username.

(b) A programmer says that they need to add authentication to the algorithm.
Explain what is meant by authentication in this situation.
Making sure the user is who they say they are by adding passwords and usernames etc. It
would also be checking to see if the passwords and suernames fit the criteria to ensure security.

1
Homework 2 Defensive design
Unit 8 Logic and languages

(c) Explain three techniques that have been used in the program to make it
more maintainable.
Technique 1:
Creating a variable that could return false or true depending on the outcome rather than a
direct return which allows for the return value to be changed or modified for other purposes.

Technique 2:
Creating a seperate function which can be edited and removed and this allows for variables
to remain local and for the code to be easier to read and change.

Technique 3:
Using two different variable names for inside the function and outside it as if you want to
declare one of them to be global, this allows for that possibility without tampering with the
outside code.

(d) Explain one other technique that could be used in the program to make it more
maintainable.
Creating variable names for the upper and lower boundaries as that would make it easier to
change them rather then setting them as hard values.

[Total 12 marks]

You might also like