# Auth fails with special-character passwords

Symptom: the user and password are definitely right (you just created them), but auth fails with `bad auth : Authentication failed`. The password contains `@`, `/`, `:`, `?`, `#`, or `%`.

## Confirm

Look at the password. If it contains any URI-reserved character, the driver parses the connection string wrong: `@` ends the user-info section early, `/` starts a new path segment, `:` splits user from password in the wrong place. The server then receives a mangled password.

## Fix

URL-encode only the password before substituting it into the string:

```js
const uri = template.replace('[password]', encodeURIComponent(password));
```

`p@ss/w:rd` becomes `p%40ss%2Fw%3Ard`. Never encode the whole URI; that breaks the scheme and hosts.

## Verify

Connect with the encoded string. Then, to stop this class of bug forever, generate future passwords from a URI-safe alphabet (letters and digits plus a few safe symbols like `-` and `_`).