Generating secure session tokens

JavaScript Nov 1, 2022

In the real world, it's very important not to use insecure session tokens. Session tokens are random characters which results in a unique value which will identify a user. If these are short, they can easily be guessed which can result in your users accounts being compromised.

Here's how to make secure tokens with crypto:

const crypto = require("crypto"); const id = crypto.randomBytes(16).toString("hex");

And that's it!

Tags