gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
Give me an example of a simple Python function for create login
- User
Give me an example of a simple Python function for create login
- Assistant
Certainly! Below is an example of a simple Python function to create a login system. This example utilizes a basic dictionary to store usernames and passwords for demonstration purposes. In a real-world application, you should use a secure database and hashing for storing passwords.
# A dictionary to store user credentials user_credentials = { 'user1': 'password1', 'user2': 'password2', # Add more users as needed } def login(username, password): """ Function to authenticate a user by checking username and password. Parameters: username (str): The username of the user trying to log in password (str): The password of the user trying to log in Returns: str: A success message if credentials match, else an error message """ if username in user_credentials: if user_credentials[username] == password: return "Login successful!" else: return "Invalid password." else: return "Username does not exist." # Example usage if __name__ == "__main__": # Simulate user input input_username = input("Enter your username: ") input_password = input("Enter your password: ") # Attempt to login result = login(input_username, input_password) print(result)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.