📖 Scenario: You have a small Raspberry Pi device connected to sensors in your home. This device collects data like temperature and humidity. You want to make sure only trusted users can access this data and that the device is safe from hackers.
🎯 Goal: Build a simple program that stores sensor data securely and only shows data if the correct password is given. This teaches why security is important for devices like Raspberry Pi in real life.
📋 What You'll Learn
Create a dictionary called sensor_data with exact keys 'temperature' and 'humidity' and their values
Create a variable called password with the exact value 'secure123'
Write a function called check_access that takes a password and returns True if it matches password, else False
Print the sensor data only if the password is correct, otherwise print 'Access denied'
💡 Why This Matters
🌍 Real World
IoT devices like Raspberry Pi collect important data that should only be accessed by trusted users to prevent misuse or hacking.
💼 Career
Understanding basic security helps in roles like IoT developer, system administrator, or cybersecurity specialist to protect devices and data.
Progress0 / 4 steps
1
Create sensor data dictionary
Create a dictionary called sensor_data with these exact entries: 'temperature': 22.5 and 'humidity': 45
Raspberry Pi
Hint
Use curly braces {} to create a dictionary with keys and values.
2
Set the password variable
Create a variable called password and set it to the exact string 'secure123'
Raspberry Pi
Hint
Use an equals sign = to assign the string to the variable.
3
Write the access check function
Write a function called check_access that takes one parameter input_password and returns True if input_password equals password, otherwise returns False
Raspberry Pi
Hint
Use def to define the function and compare the input to the stored password.
4
Print sensor data if password is correct
Write code to ask the user for a password using input(). Use check_access to verify it. If correct, print sensor_data. Otherwise, print 'Access denied'
Raspberry Pi
Hint
Use input() to get user input and an if statement to check access.
Practice
(1/5)
1. Why is it important to secure Raspberry Pi devices used in IoT projects?
easy
A. To reduce the device's power consumption
B. To make the device run faster
C. To prevent unauthorized access and protect data
D. To increase the device's screen brightness
Solution
Step 1: Understand the role of security in IoT
Security helps keep devices safe from hackers and unauthorized users who might steal data or control the device.
Step 2: Identify the main goal of securing devices
The main goal is to protect data and device functionality, not to affect speed, brightness, or power use.
Final Answer:
To prevent unauthorized access and protect data -> Option C
Hint: Security means keeping strangers out and data safe [OK]
Common Mistakes:
Confusing security with device performance
Thinking security changes hardware features
Ignoring data protection importance
2. Which of the following is the correct way to set a password on a Raspberry Pi to improve security?
easy
A. Use the command passwd and enter a strong password
B. Use the command setpassword with any password
C. Change the password by editing /etc/passwd manually
D. No need to set a password if the device is offline
Solution
Step 1: Identify the standard command for changing passwords
The passwd command is the official and safe way to change passwords on Raspberry Pi.
Step 2: Evaluate other options for correctness
setpassword is not a valid command; editing /etc/passwd manually is risky and not recommended; offline devices still need passwords for security.
Final Answer:
Use the command passwd and enter a strong password -> Option A
Quick Check:
Use passwd command = Correct password setting [OK]
Hint: Use the official passwd command for passwords [OK]
Common Mistakes:
Trying to edit system files manually
Using non-existent commands
Assuming offline means no security needed
3. What will be the output of this Python code running on a Raspberry Pi that checks if a device is secure based on password strength?
password = 'abc123'
if len(password) >= 8 and any(c.isdigit() for c in password) and any(c.isalpha() for c in password):
print('Secure')
else:
print('Not Secure')
medium
A. Secure
B. Not Secure
C. SyntaxError
D. No output
Solution
Step 1: Check password length condition
The password 'abc123' has length 6, which is less than 8, so the first condition fails.
Step 2: Evaluate the full if condition
Since the length condition is false, the whole condition is false, so the else block runs.
Final Answer:
Not Secure -> Option B
Quick Check:
Password length < 8 = Not Secure [OK]
Hint: Check length first; less than 8 means not secure [OK]
Common Mistakes:
Ignoring length check
Assuming presence of digits and letters is enough
Confusing syntax with logic errors
4. Find the error in this Raspberry Pi Python script that tries to block unauthorized IP addresses: