Lesson 5: Password generator
About this lesson
This is the fifth in a series of lessons to transition from visual coding to text-based coding with a general-purpose programming language.
Year band: 5-6, 7-8Curriculum Links Assessment
Links with Digital Technologies Curriculum Area
|Processes and Production Skills||5-6||
Design, modify and follow simple algorithms involving sequences of steps, branching, and iteration (repetition) (ACTDIP019)
Design algorithms represented diagrammatically and in English, and trace algorithms to predict output for a given input and to identify errors (ACTDIP029)
Implement and modify programs with user interfaces involving branching, iteration and functions in general-purpose programming language (ACTDIP030)
Students undertake a self-reflection of the programming task. The teacher can use the completed self-assessments to assist in summative assessment.
Many experts advise that passwords should not be re-used for different sites and services.
In pairs, try to estimate how many different sites and services you currently use that require a login. These might include:
- social media
- personal device access
WARNING: For security reasons, students should never share passwords with each other, nor should they disclose the method they personally use for managing or remembering their passwords.
Next, consider which of those services you would consider to be important. That is, if someone else were to gain access, they would have key identity, health or financial information about you.
As a class, discuss the dangers of using the same password for two different services. What might be a solution, and what are the pros and cons?
This clip from ABC’s The Checkout discusses the problem of remembering passwords, and one solution suggested by some experts.
Image credit: AbsolutVision/pixabay
Learning map and outcomes
In this lesson, students will:
- practise creating and using arrays (also called lists)
- explore the design of a password generator that combines three words, with each word chosen randomly from a separate list
- plan and code the password generator
Begin by watching the video introducing arrays:
- Examine this pseudocode carefully, then write the output of the program, that is, exactly what it will display on screen:
BEGIN mountains ← [‘Mount Everest’, ‘Mount Kosciuszko’, ‘Mont Blanc’] continents ← [‘Asia’, ‘Australia’, ‘Europe’] heights ← [8848, 2228, 4809] Display “Here’s some information about ”, mountains Display “It can be found on the continent of ”, continents Display “Its height in metres is ”, heights Display “But the tallest mountain in the world is ”, mountains END
In Scratch, items in a list are numbered starting from 1. See an example here.
But in Python, list elements are numbered starting from 0. The first entry ‘Canberra’ has position 0. The last entry ‘Rome’ has position 4.
capitals = ['Canberra', 'Paris', 'London', 'Kinchasa', 'Rome'] print(capitals)
This program displays “Rome”.
var capitals = ['Canberra', 'Paris', 'London', 'Kinchasa', 'Rome']; alert(capitals);
It is easy to forget that the position of the last item is 1 less than the array’s length. Off-by-one bugs are among the most common coding bugs, even for experienced programmers.
Here’s some information about Mont Blanc
It can be found on the continent of Europe
Its height in metres is 4809
But the tallest mountain in the world is Mount Everest
For more on setting up and choosing a language, see Setting Up.
Step 1: Solution development
This video demonstrates coding a simple decision maker program, then expands it to a Magic 8 Ball program.
Step 2: Coding the program
Step 3: Tinker task
Modify your password generator program to incorporate more word choices. There should be 10 adjectives, 8 nouns and 12 numbers.
Next, add an array of special characters (‘$’, ‘!’, ‘#’, ‘%’, ‘*’) and choose one of these at random to join to the end of the generated password.
Lastly, edit your program so that it asks the user at the beginning if they want to include the special character or not.
These challenges use the skills covered so far. By writing or modifying their own programs, students have an opportunity to demonstrate Application and Creation.
Create a program to generate and display information about a fantasy game character.
- Write out the algorithm in pseudocode first.
Choose the following basics at random from pre-made lists:
- a first name (eg Ugbar, Clint, Luglug, Rohan, Marielle, Elinore)
- a surname (eg Rizrad, Deepforge, Ravenspell)
- a race (eg human, dwarf, troll, elf).
Choose some stats as random numbers between 1 and 15:
Challenge early finishers to improve the program. Here are some suggestions for improvements:
- Use specialised name lists depending on the race of the character.
- Add race bonuses (eg trolls can add +3 to their strength value).
- Develop a system for standardising characters. If the user got very unlucky with all their stat values, they should be boosted, or the player can roll again.
Create a gameshow challenge where the player must choose one of three doors to win a prize. They can choose Door no. 0, Door no. 1 or Door no. 2.
The prizes behind the doors are already set by creating an array. For example:
|0||a lifetime supply of gum ointment!|
|1||a new car!|
|2||a board game to take home and play with the family!|
The player chooses a door simply by entering the number 0, 1 or 2, then their prize is displayed. Note: if using Scratch, the door numbers can be 1, 2 and 3.
Challenge 3 (Optional)
Create a different type of password generator that builds up from single letters, numbers and special characters.
Many online services have strict rules about passwords. For example:
“Passwords should be 10 characters long. They should contain at least one character from each of the following sets: lowercase letters, uppercase letters, numerals and special characters. Passwords should not contain dictionary words or common names.”
Your new password generator must follow the rules above. This does not require any new knowledge than for the password generator introduced in this lesson, but it will take more work to type out the contents of all four arrays.
Lower case example:
Upper case example:
Challenge 4 (Optional)
Create a shopping list helper that uses an array. Prompt the user three times to type in an item, then display the complete list.
eg Enter the first item: apples Enter the second item: milk Enter the third item: frozen veggies Your shopping list contains apples, milk and frozen veggies.
For this challenge, you could start with an array containing three 'nothing' strings, then replace them with actual words.
- Setting up online environments
- Online environments for coding in each language
- Cheat sheets listing basic commands for coding: