> For the complete documentation index, see [llms.txt](https://security.navidnaf.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://security.navidnaf.com/platform-9-3-4/auth-auth/authentication.md).

# 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="/files/boZT2gKyM83ukwjFkY3k" 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.
