📚 Hands-On Case Study: Password Strength Checker | 案例分析实战演练:密码强度检查器
In this article, we will work through a complete case study to design a password strength checker. You will learn how to apply computational thinking and basic programming concepts to solve a real-world problem step by step. This hands-on practice is ideal for Year 8 students following the CIE computing curriculum.
在本文中,我们将完成一个完整的案例研究,设计一个密码强度检查器。你将学习如何应用计算思维和基本的编程概念,一步步解决一个实际问题。这种动手实践非常适合遵循CIE计算机课程的八年级学生。
1. Introduction to the Case Study | 案例研究简介
In this hands-on case study, we will design a simple program to check the strength of a password. This is a common real-world problem that helps us practise computational thinking skills such as decomposition, pattern recognition, and algorithm design. By breaking down the problem, we can create a solution step by step.
在这个动手实践的案例研究中,我们将设计一个简单的程序来检查密码的强度。这是一个常见的实际问题,可以帮助我们练习分解、模式识别和算法设计等计算思维技能。通过将问题分解,我们可以一步一步地创建解决方案。
2. Understanding the Problem | 理解问题
Our program must ask the user to enter a password. It should then analyse the password and decide whether it is weak, medium, or strong based on certain rules. A weak password is too short (fewer than 8 characters). A strong password is at least 8 characters long and contains both letters and digits. A medium password is at least 8 characters long but has only letters or only digits. We need to output the strength level and perhaps a suggestion to improve it.
我们的程序必须要求用户输入一个密码。然后,它应该分析密码并根据特定规则判断它是弱、中等还是强。弱密码太短(少于8个字符)。强密码至少8个字符长,并且同时包含字母和数字。中等密码至少8个字符长,但只包含字母或只包含数字。我们需要输出强度等级,也许还要给出改进建议。
3. Requirements and Specifications | 需求与规格说明
Before coding, we must list clear requirements. The program will: 1) Prompt for a password. 2) Read the password from the user. 3) Check the length. 4) Check whether it contains at least one letter. 5) Check whether it contains at least one digit. 6) Output 'Weak', 'Medium' or 'Strong'. 7) Optionally, give a tip like 'Use at least 8 characters and mix letters with numbers.'
在编码之前,我们必须列出清晰的需求。程序将:1) 提示输入密码。2) 从用户读取密码。3) 检查长度。4) 检查是否包含至少一个字母。5) 检查是否包含至少一个数字。6) 输出'弱'、'中等'或'强'。7) 可选地,给出一个提示,例如'请使用至少8个字符,并混合字母和数字'。
4. Inputs and Outputs | 输入与输出
The only input is a string value: the password. It can include any characters the user types, but our checks focus on letters (A-Z, a-z) and digits (0-9). Spaces and symbols are ignored for this basic version. The output is a message stating the strength. Test cases: Input 'abc' → 'Weak'; Input 'abcdefgh' (only letters, length 8) → 'Medium'; Input 'pass1234' → 'Strong'.
唯一的输入是一个字符串值:密码。它可以包含用户输入的任何字符,但我们的检查专注于字母(A-Z,a-z)和数字(0-9)。在这个基础版本中,空格和符号被忽略。输出是一条说明强度的消息。测试案例:输入 'abc' → '弱';输入 'abcdefgh'(仅字母,长度8)→ '中等';输入 'pass1234' → '强'。
5. Algorithm Design: Flowchart | 算法设计:流程图
steps are: Start → Input password → Calculate length → Check length < 8? If yes, output 'Weak' igit, set has_digit true → After loop, check if has_letter AND has_digit are true → If yes, output 'Strong'; otherwise output 'Medium' → End.
我们可以用流程图来表示算法。步骤如下:开始 → 输入密码 → 计算长度 → 检查长度 < 8?如果是,输出'弱'并停止。如果否,将 has_letter 和 has_digit 初始化为 false → 循环遍历每个字符:如果字符是字母,将 has_letter 设为 true;如果是数字,将 has_digit 设为 true → 循环后,检查 has_letter 和 has_digit 是否都为 true → 如果是,输出'强';否则输出'中等' → 结束。
6. Pseudocode for the Password Checker | 密码检查器伪代码
Here is the pseudocode that matches the flowchart:
PRINT "Enter your password:"
INPUT password
len ← LENGTH(password)
IF len < 8 THEN
PRINT "Weak"
ELSE
has_letter ← FALSE
has_digit ← FALSE
FOR i ← 0 TO len-1
char ← password[i]
IF char ≥ 'A' AND char ≤ 'Z' OR char ≥ 'a' AND char ≤ 'z' THEN
p; has_letter ← TRUE
END IF
IF char ≥ '0' AND char ≤ '9' THEN
sp; has_digit ← TRUE
END IF
NEXT i
IF has_letter AND has_digit THEN
PRINT "Strong"
ELSE
PRINT "Medium"
END IF
END IF
以下是匹配流程图的伪代码:
打印 "请输入你的密码:"
输入 password
len ← 长度(password)
如果 len < 8 则
打印 "弱"
否则
has_letter ← 假
has_digit ← 假
对于 i 从 0 到 len-1
char ← password[i]
如果 char ≥ 'A' 且 ≤ 'Z' 或 char ≥ 'a' 且 ≤ 'z' 则
has_letter ← 真
结束如果
如果 char ≥ '0' 且 char ≤ '9' 则
has_digit ← 真
结束如果
下一个 i
如果 has_letter 且 has_digit 则
打印 "强"
否则
打印 "中等"
&
Published by TutorHao | Year 8 Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

或截图后用「扫一扫 → 相册」选择本图