Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import crypto from "crypto";
- class CSRF {
- private store: string[] = [];
- constructor() {}
- createToken() {
- const token = crypto.randomBytes(64).toString("hex");
- this.store.push(token);
- return token;
- }
- checkToken(token: string): Promise<boolean> {
- return new Promise((resolve, reject) => {
- let i = this.store.indexOf(token);
- i > -1
- ? (() => {
- delete this.store[i];
- resolve(true);
- })()
- : reject(false);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement