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

Scopes Task

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)
3 views2 pages

Scopes Task

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

Class Task: Secure Access Control System (Encapsulation with Closures)

Task Description:z

You need to design a function called secure_vault(password), which creates and returns
another function (access_vault) that grants access to a secret message only if the correct
password is entered.

 The password should be stored securely inside a closure, preventing unauthorized


modifications.
 The inner function (access_vault) should verify the password and return either
the secret message or an access denied message.
 The secret message should be inaccessible from outside the closure.

Requirements:

1. Inputs:

 A password (string) should be passed when creating the vault.


 A user-entered password (string) should be provided when attempting to access the
vault.

2. Outputs:

 If the entered password matches the stored password, return:


✅ "Access Granted: [SECRET_MESSAGE]"
 If the entered password is incorrect, return:
❌ "Access Denied"

3. Constraints:

 The secret message should be stored inside the closure, making it inaccessible from
outside the function.
 The password should not be stored in a global variable.
 The solution must use closures for data protection.

Expected Functionality Example:


# Creating a secure vault with a password
vault = secure_vault("my_secret_password")

# Attempting access with incorrect password


print(vault("wrong_password"))
# Output: ❌ Access Denied
# Attempting access with the correct password
print(vault("my_secret_password"))
# Output: ✅ Access Granted: Top Secret Files

Assessment Criteria:

Criteria Description
The function properly retains the secret message within an
Correct Use of Closures
enclosing scope.
The password and secret message are not accessible globally or
Encapsulation
modifiable outside the closure.
Correct Password
The function correctly grants or denies access based on user input.
Validation
Code Readability & The code is well-organized, uses meaningful function names, and
Structure follows best practices.

Extension Task (Bonus Challenge 💡)

Modify the function to limit the number of incorrect attempts (e.g., maximum 3 tries). If
the user exceeds this limit, permanently lock access to the vault.

Example Output (Bonus Challenge):

vault = secure_vault("1234")

print(vault("0000")) # ❌ Access Denied


print(vault("1111")) # ❌ Access Denied
print(vault("2222")) # ❌ Access Denied
print(vault("1234")) # ❌ Access Denied (Vault permanently locked)

You might also like