---
title: "Avoid writing your own password and token · Agent Wranglers"
url: https://agentwranglers.se/playbook/stack/product-services/no-own-auth-code
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Avoid writing your own password and token code

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

For AI agents: [llms.txt](https://agentwranglers.se/llms.txt) is a short guide that sends you to the rules your problem needs, and [rules.json](https://agentwranglers.se/playbook/stack/rules.json) holds every rule of this playbook as JSON.

- Level: Avoid
- Chapter: [Product services](https://agentwranglers.se/playbook/stack/product-services)
- Rule: Never write your own password hashing, session tokens, WebAuthn parsing or OpenID Connect handling.
- Applies when: The project it has user accounts.
- How: Each of these has small details that decide whether accounts are safe, and a mistake shows no symptom until an attacker finds it. Maintained libraries and services have had those mistakes found and fixed by thousands of users. Use the passkey library or Keycloak above, or a framework's own sign-in. Pick between them as [Decide whether a provider or a library runs sign-in](https://agentwranglers.se/playbook/accounts/sign-in-methods/auth-provider-or-library) says. Store passwords as [Store passwords with a slow hash](https://agentwranglers.se/playbook/adversarial-testing/access-and-accounts/password-storage) says.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
import argon2 from 'argon2';

export const hashPassword = (password) => argon2.hash(password);
```

### Python example

```python
from argon2 import PasswordHasher

hasher = PasswordHasher()

def hash_password(password: str) -> str:
    return hasher.hash(password)
```

## Related rules

- [Decide whether a provider or a library runs sign-in](https://agentwranglers.se/playbook/accounts/sign-in-methods/auth-provider-or-library) in Accounts
- [Store passwords with a slow hash](https://agentwranglers.se/playbook/adversarial-testing/access-and-accounts/password-storage) in Security testing

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/stack/product-services/no-own-auth-code">Agent Wranglers software choices playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Avoid handling card numbers yourself](https://agentwranglers.se/playbook/stack/product-services/no-own-card-handling)
- Next: [Use Better Auth or django-allauth for sign-in inside the app](https://agentwranglers.se/playbook/stack/product-services/sign-in-library)
- [Product services](https://agentwranglers.se/playbook/stack/product-services)
