---
title: Blocking the Account Username as a Chat Nickname
updatedAt: 2026-12-01T13:03:59.492Z
---

Fetch the complete documentation index at: https://docs.watchers.io/llms.txt

# Blocking the Account Username as a Chat Nickname

Some operators don't want players to show their account username in the chat: a username is half of the login credentials. With the `usernameHash` parameter, the chat can stop a player from choosing their own account username as their chat nickname.

Watchers never receives the username itself, only a keyed hash of it.

## How it works

- A player can't use their own account username as their chat nickname, neither during onboarding nor when they change the nickname later. The chat shows: "This nickname isn't available. Please don't use your account username as your nickname." The text is translated into the chat language.
- If a player's current nickname already matches their username, the next time they open the chat the nickname is replaced with their generated system nickname and they are asked to choose a new one.
- Only the player's own username is checked. A nickname that matches another player's username is allowed.
- Matching ignores letter case, accents and spaces at both ends. Only exact matches are blocked: similar variants (extra characters, digits) are allowed.

## What you need to do

1. Get the project secret from Watchers. We send it to you separately, never in a public channel. If you prefer to use your own secret, send it to us the same way and we set it for your project.
2. On your backend, compute `usernameHash` for each logged-in player (see below).
3. Add `usernameHash` to the chat URL next to `userId` every time the chat is opened.

```
https://<chat-host>/?apikey=<API_KEY>&userId=<USER_ID>&roomId=<ROOM_ID>&usernameHash=<HASH>
```

The parameter name is case-insensitive. Without the parameter, or with a value that is not 64 hexadecimal characters, the chat works exactly as before.

Compute the hash on your backend only. The secret must never reach the browser: anyone who has it can check guessed usernames against hashes.

## How to compute usernameHash

1. Take the player's account username.
2. Normalize it:
   - trim whitespace at both ends;
   - apply Unicode NFD;
   - remove combining marks U+0300 to U+036F;
   - lowercase, locale-independent (Java `toLowerCase(Locale.ROOT)`, C# `ToLowerInvariant()`, JavaScript `toLowerCase()`).
3. Compute HMAC-SHA256:
   - key: the secret string as UTF-8 bytes (don't hex-decode it);
   - message: the normalized username as UTF-8 bytes.
4. Output the result as lowercase hex, 64 characters.

### Reference implementation (Node.js)

```js
const crypto = require('crypto');

const normalize = (login) =>
  login.trim().normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();

const usernameHash = (secret, login) =>
  crypto
    .createHmac('sha256', Buffer.from(secret, 'utf8'))
    .update(normalize(login), 'utf8')
    .digest('hex');
```

### Test vectors

Example secret `example-secret-for-tests` (not your real secret):

| Username | Normalized | usernameHash |
|---|---|---|
| `José.Pérez` | `jose.perez` | `a386891fae1da6dee67139c66b1bd211632da647d635890b59d7144faa26fd45` |
| `  JOSÉ.Pérez ` | `jose.perez` | `a386891fae1da6dee67139c66b1bd211632da647d635890b59d7144faa26fd45` |
| `maria.lopez` | `maria.lopez` | `f7caa5acdf05daef5bf3d5addc059ba1c23e04642c88ba0a55456991bb23da1a` |
| `İstanbul` | `istanbul` | `7b3a8147e4134f5cfe8bfcde5ff838e6c8ba2af99b8d3101a0cde24185a05d4b` |
| `Straße` | `straße` | `a87d71f354e8ed2f510a40a437658b53670ca444a864b0ee7a836c2aff677e6f` |
| `Łódź` | `łodz` | `dee2462c55af732765a7af40b92c2599d8923931e262ba5262030ed239272a7f` |

NFD does not decompose `ß` or `ł`, so they stay as they are.

## Changing the secret

We can rotate the secret on request. After a rotation, each player's hash updates the next time they open the chat with the new value.

## Related pages

- [Avatars and Nicknames](https://docs.watchers.io/docs/avatars-and-user-profile)
- [Embedding Configuration](https://docs.watchers.io/docs/get-parameters)
