# Step 4: Identify users

URL: https://www.digia.tech/docs/developer/moengage/identify-users

MoEngage Change your setup in the sidebar
Set the user ID and attributes in Digia Engage after login and clear them on logout, so MoEngage campaigns reach the right user.

Call this right after you identify the user in MoEngage.

Tell Digia who the user is after login, and clear it on logout.

## Set the user

Call `setUserId` after login. Pass the user hash too if you turned on user verification . Call `setUserAttributes` for anything your campaigns should target, such as city or plan.

- React Native - Android - iOS (Swift) - Flutter

```tsx
// After login
Digia.setUserId('user-123', { userHash });
Digia.setUserAttributes({ city: 'Pune', plan: 'gold' });

// On logout
Digia.clearUserId();
```

```kotlin
// After login
Digia.setUserId("user-123", userHash = userHash)
Digia.setUserAttributes(mapOf("city" to "Pune", "plan" to "gold"))

// On logout
Digia.clearUserId()
```

```swift
// After login
Digia.setUserId("user-123", userHash: userHash)
Digia.setUserAttributes(["city": "Pune", "plan": "gold"])

// On logout
Digia.clearUserId()
```

```dart
// After login
await Digia.setUserId('user-123', userHash: userHash);
await Digia.setUserAttributes({'city': 'Pune', 'plan': 'gold'});

// On logout
await Digia.clearUserId();
```

- The user ID is remembered across launches. Set it once after login.
- Attributes add up. Each call adds to what is already set.
- Attribute values can be text, numbers, true/false, or a list of text.
- `clearUserId` clears the user and their attributes. Also clear any inline content you kept. SeeManaging Inline Content .

## Verify your users

Your app's API key ships inside the app, so anyone can claim to be any user ID. User verification fixes that. Your server signs the user ID with a secret. The app sends the result, the user hash, with `setUserId` . Digia checks it.

Gamification needs a user ID. When verification is on, it needs the hash too. Turn verification on for any project that gives out rewards.

### Turn it on

1. In the dashboard, open **Project settings → User verification** .
2. Choose **Set up** , then **Copy** .
3. Keep the secret on your server. Never put it in the app.

### Compute the hash on your server

The hash is the HMAC-SHA256 of the user ID, with the secret as the key, as lowercase hex. Use the user ID exactly as you pass it to `setUserId` . Send the hash to the app, for example in your login response.

- Node.js - Python

```js
import { createHmac } from 'node:crypto';

const userHash = createHmac('sha256', process.env.DIGIA_USER_SECRET)
  .update(userId)
  .digest('hex');
```

```python
import hashlib
import hmac
import os

user_hash = hmac.new(
    os.environ["DIGIA_USER_SECRET"].encode(),
    user_id.encode(),
    hashlib.sha256,
).hexdigest()
```
