diff --git a/demo/src/__init___.py b/demo/src/__init___.py new file mode 100644 index 0000000..e69de29 diff --git a/demo/src/password_checker.py b/demo/src/password_checker.py new file mode 100644 index 0000000..5a7885a --- /dev/null +++ b/demo/src/password_checker.py @@ -0,0 +1,58 @@ +class PasswordChecker: + def __init__(self): + self.min_length = 8 + self.special_chars = "!@#$%^&*()_+-=[]{}|;:,.<>?" + + def check_strength(self, password): + """ + Bug: The function doesn't properly check for the presence of numbers + It only checks if there's a digit in the first position + """ + score = 0 + feedback = [] + + # Check length + if len(password) >= self.min_length: + score += 1 + else: + feedback.append("Password should be at least 8 characters long") + + # Check for uppercase + if any(c.isupper() for c in password): + score += 1 + else: + feedback.append("Password should contain at least one uppercase letter") + + # Bug: Incorrect number checking + if password[0].isdigit(): # Bug is here - only checks first character + score += 1 + else: + feedback.append("Password should contain at least one number") + + # Check for special characters + if any(c in self.special_chars for c in password): + score += 1 + else: + feedback.append("Password should contain at least one special character") + + strength = { + 0: "Very Weak", + 1: "Weak", + 2: "Moderate", + 3: "Strong", + 4: "Very Strong" + } + + return { + "score": score, + "strength": strength[score], + "feedback": feedback + } + +# Usage Example +if __name__ == "__main__": + checker = PasswordChecker() + test_password = "2weakpass" + result = checker.check_strength(test_password) + print(f"Password Strength: {result['strength']}") + print("Feedback:", "\n".join(result['feedback'])) \ No newline at end of file diff --git a/demo/src/student_management.py b/demo/src/student_management.py new file mode 100644 index 0000000..b0a8b14 --- /dev/null +++ b/demo/src/student_management.py @@ -0,0 +1,49 @@ +class Student: + def __init__(self, roll_no, name, age, grade): + self.roll_no = roll_no + self.name = name + self.age = age + self.grade = grade + +class StudentManagementSystem: + def __init__(self): + self.students = [] + + def add_student(self, roll_no, name, age, grade): + """ + Bug: Function doesn't properly check for duplicate roll numbers + It compares strings instead of integers for roll numbers + """ + # Bug: Incorrect string comparison instead of integer comparison + if any(str(student.roll_no) == str(roll_no) for student in self.students): + return False, "Roll number already exists" + + new_student = Student(roll_no, name, age, grade) + self.students.append(new_student) + return True, "Student added successfully" + + def get_student(self, roll_no): + for student in self.students: + if student.roll_no == roll_no: + return student + return None + + def display_all_students(self): + if not self.students: + return "No students registered" + + result = "Student List:\n" + for student in self.students: + result += f"Roll No: {student.roll_no}, Name: {student.name}, " + result += f"Age: {student.age}, Grade: {student.grade}\n" + return result + +# Usage Example +if __name__ == "__main__": + sms = StudentManagementSystem() + + # These additions will work even though they should be duplicates + sms.add_student("001", "John Doe", 18, "A") + sms.add_student(1, "Jane Smith", 19, "B") # Should be rejected but won't be + + print(sms.display_all_students()) \ No newline at end of file diff --git a/demo/src/todo_list.py b/demo/src/todo_list.py new file mode 100644 index 0000000..b19275c --- /dev/null +++ b/demo/src/todo_list.py @@ -0,0 +1,63 @@ +class Task: + def __init__(self, id, title, description): + self.id = id + self.title = title + self.description = description + self.status = "pending" # Can be "pending", "in_progress", or "completed" + self.is_completed = False # Bug: Redundant status tracking + +class TodoList: + def __init__(self): + self.tasks = [] + self.next_id = 1 + + def add_task(self, title, description): + task = Task(self.next_id, title, description) + self.tasks.append(task) + self.next_id += 1 + return task.id + + def update_status(self, task_id, new_status): + """ + Bug: Status inconsistency between status field and is_completed flag + """ + task = self.get_task(task_id) + if not task: + return False, "Task not found" + + if new_status not in ["pending", "in_progress", "completed"]: + return False, "Invalid status" + + task.status = new_status + # Bug: is_completed flag is not updated + # This creates inconsistency in task completion status + return True, "Status updated successfully" + + def get_task(self, task_id): + for task in self.tasks: + if task.id == task_id: + return task + return None + + def list_tasks(self): + if not self.tasks: + return "No tasks found" + + result = "Task List:\n" + for task in self.tasks: + result += f"ID: {task.id}, Title: {task.title}\n" + result += f"Description: {task.description}\n" + result += f"Status: {task.status}, Completed: {task.is_completed}\n" + result += "-" * 50 + "\n" + return result + +# Usage Example +if __name__ == "__main__": + todo = TodoList() + + # Add a task and update its status + task_id = todo.add_task("Complete project", "Finish the bug bounty project") + todo.update_status(task_id, "completed") + + print(todo.list_tasks()) + # Will show inconsistency: status="completed" but is_completed=False \ No newline at end of file