Complete the code to check if the entered password matches the stored password.
if entered_password [1] stored_password: print("Access granted") else: print("Access denied")
We use == to compare if two passwords are the same.
Complete the code to ask the user for their username.
username = input([1])
The prompt should ask for the username, so the message is "Enter your username: ".
Fix the error in the code to securely check the password using hashing.
import hashlib hashed_input = hashlib.sha256(entered_password.encode()).hexdigest() if hashed_input [1] stored_hashed_password: print("Access granted") else: print("Access denied")
To compare hashed passwords, use == to check equality.
Fill both blanks to create a dictionary comprehension that stores usernames and their hashed passwords only if the password length is greater than 5.
user_hashes = {user: hashlib.sha256([1].encode()).hexdigest() for user, [2] in users.items() if len(password) > 5}Both blanks refer to the password variable, which is named 'password' in the loop.
Fill all three blanks to create a function that checks if a username exists and the password matches the stored hash.
def authenticate([1], [2]): if [1] in user_db and hashlib.sha256([2].encode()).hexdigest() == user_db[[1]]: return True return False
The function takes username and password as parameters. The username is checked in the database and used to get the stored hash.