# Authentication · Chromia for EVM developers · Learn Chromia

> This lesson uses a basic Twitter clone to compare how authentication works in Solidity and in Rell.

Source: https://chromia.com/learn/chromia-for-evm-developers/compare-authentication/

Chromia for EVM developersLesson 4 of 8

1. [01Chromia for EVM developers](https://chromia.com/learn/chromia-for-evm-developers/introduction/)
2. [02Explore assets and transfers](https://chromia.com/learn/chromia-for-evm-developers/asset-transfer/)
3. [03Chromia dapp overview](https://chromia.com/learn/chromia-for-evm-developers/chromia-stack/)
4. [04Authentication](https://chromia.com/learn/chromia-for-evm-developers/compare-authentication/)
5. [05Core concepts](https://chromia.com/learn/chromia-for-evm-developers/concepts/)
6. [06Create a news feed dapp](https://chromia.com/learn/chromia-for-evm-developers/news-feed/)
7. [07Extend news feed dapp](https://chromia.com/learn/chromia-for-evm-developers/news-feed-follower/)
8. [08Summary](https://chromia.com/learn/chromia-for-evm-developers/summary/)

[Learn](https://chromia.com/learn/)[Chromia for EVM developers](https://chromia.com/learn/chromia-for-evm-developers/)

04 / 08

# Authentication

This lesson uses a basic Twitter clone to compare how authentication works in Solidity and in Rell.

## Solidity

Solidity has authentication built into the language. `msg.sender` gives you the address of whoever started the current function call, whether a person or a contract. You typically rely on it to authenticate callers and authorize what they can do.

Here is how you might add a post to a user's account:

Solidity

```
function createPost(string memory _text) public {
    Post memory newPost = Post(_text, block.timestamp);
    users[msg.sender].posts.push(newPost);
}
```

`msg.sender` also lets you lock down specific functions. To limit administrative functions to the account that deployed the contract, check the caller with the require function:

`require(msg.sender == owner, "Only the owner can call this function.");`

## Rell

Rell handles authentication through the FT4 library. It plays a role similar to Solidity's `msg.sender`, but you first need to configure an authentication handler. You then call `auth.authenticate()` to authenticate the caller and retrieve the user. The user has to be registered in the dapp before `auth.authenticate()` can be called.

Start by defining the auth handler as an extension:

Rell

```
import lib.ft4.auth;

@extend(auth.auth_handler)
function () = auth.add_auth_handler(
    flags = ["MySession"]
);
```

Next, add authentication to a `create_post` operation:

Rell

```
entity user {
    mutable name;
    key id: byte_array;
    key account: byte_array;
}

operation create_post(user_id : byte_array, content: text) {
    var account = auth.authenticate();
    create Post ( user @ { account }, content = content );
}
```

As in Solidity, authentication in Rell takes only a few lines and fits naturally into your operations.

To restrict an operation to an owner, define an owner user in your blockchain configuration and enforce the check with `require`:

Rell

```nolines
require(op_context.is_signer(owner), "Only the owner can call this operation");
```

To summarize how each language handles authentication:

1. **Solidity:** Relies on msg.sender to authenticate and authorize callers.
2. **Rell:** Relies on the FT4 library, calling `auth.authenticate()` to get the authenticated user.

For more on FT4 and authentication in Rell, see the
[FT4 accounts and auth descriptors documentation](https://docs.chromia.com/build/ft4/backend/accounts/accounts-and-auth-descriptors/).

Written for this site from Chromia’s public course. Code samples are the course’s own.

[← Previous**Chromia dapp overview**](https://chromia.com/learn/chromia-for-evm-developers/chromia-stack/)[Next →**Core concepts**](https://chromia.com/learn/chromia-for-evm-developers/concepts/)

On this page

* [Solidity](#solidity)
* [Rell](#rell)
