SHARE
TWEET

Untitled

a guest Oct 16th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import crypto from "crypto";
  2.  
  3. class CSRF {
  4.   private store: string[] = [];
  5.  
  6.   constructor() {}
  7.  
  8.   createToken() {
  9.     const token = crypto.randomBytes(64).toString("hex");
  10.     this.store.push(token);
  11.     return token;
  12.   }
  13.  
  14.   checkToken(token: string): Promise<boolean> {
  15.     return new Promise((resolve, reject) => {
  16.       let i = this.store.indexOf(token);
  17.       i > -1
  18.         ? (() => {
  19.             delete this.store[i];
  20.             resolve(true);
  21.           })()
  22.         : reject(false);
  23.     });
  24.   }
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top