Complete the code to check if a password is at least 8 characters long.
if len(password) [1] 8: print("Password length is sufficient")
The password should be at least 8 characters, so we check if length is greater than or equal to 8.
Complete the code to verify if the entered password matches the stored password.
if entered_password [1] stored_password: print("Access granted") else: print("Access denied")
Passwords must be exactly equal to grant access, so we use '=='.
Fix the error in the code to hash a password using SHA-256.
import hashlib hashed = hashlib.sha256([1].encode()).hexdigest() print(hashed)
The password string must be encoded before hashing. The code calls encode() after passing the string, so just pass the password variable.
Fill both blanks to create a dictionary comprehension that stores usernames and their hashed passwords only if the password length is at least 8.
hashed_passwords = {user: hashlib.sha256(passwd[1]).hexdigest() for user, passwd in users.items() if len(passwd) [2] 8}Passwords must be encoded before hashing, so use '.encode()'. The condition checks for passwords with length greater than or equal to 8.
Fill all three blanks to create a dictionary comprehension that stores usernames in uppercase, their passwords, and filters only those with passwords containing more than 6 characters.
filtered_users = [1]: [2] for [3], pwd in users.items() if len(pwd) > 6
Usernames are converted to uppercase with 'user.upper()'. Passwords are stored as 'pwd'. The loop variable for usernames is 'user'.
