# Authentication

Authentication ensures only authorized processes and users access protected IT resources, like computer systems, databases, networks, websites, and web-based services. After authentication, an authorization process determines access to specific resources. If authenticated but not authorized, access is denied.

In a conventional authentication process, users input their credentials, like a username and password. The authentication system then checks a user directory, stored either locally or on an authentication server. Upon a match, access to the system is granted. In the subsequent stage, user permissions dictate access to objects or operations, alongside other rights such as access times and rate limits.

<figure><img src="https://244896893-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTy5fNwfsaV6DbqjnheTF%2Fuploads%2Fo3N89jfxmQGC0zWn7y8V%2FBlank%20board%20-%20Page%201.png?alt=media&#x26;token=24b5346f-b7f2-48dd-a01b-8b73e7e21230" alt=""><figcaption><p>General Authentication Process</p></figcaption></figure>

## Authentication System Design

```python
# User database (can be replaced with a database or external source)

user_database = {
    "user1": "password1",
    "user2": "password2",
    "user3": "password3"
}

def authenticate(username, password):
    if username in user_database and user_database[username] == password:
        return True
    else:
        return False

# Test authentication
username_input = input("Enter your username: ")
password_input = input("Enter your password: ")

if authenticate(username_input, password_input):
    print("Authentication successful!")
else:
    print("Authentication failed. Invalid username or password.")

```

This Python code implements a basic user authentication system using a username and password. The system utilizes a dictionary named `user_database` to store predefined username-password pairs. The `authenticate` function takes user input for a username and password and checks if the provided username exists in the database and if the corresponding password matches. If both conditions are met, the function returns `True`, indicating successful authentication; otherwise, it returns `False`. The main part of the code prompts the user to input their username and password, and based on the result of the `authenticate` function, it outputs either "Authentication successful!" or "Authentication failed. Invalid username or password.". This code demonstrates a straightforward approach to user authentication in Python.
