SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var express = require("express");
  2. var crypto = require("crypto");
  3.  
  4. var Sequelize =  require('sequelize');
  5. var config = require("./config.js");
  6.  
  7. var app = express();
  8. var seq = new Sequelize(config.database_uri);
  9.  
  10.  
  11. const Word = seq.define("word", {
  12.     uuid: {type: Sequelize.UUID, primaryKey: true, defaultValue: Sequelize.UUIDV4, allowNull: false},
  13.     word: {type: Sequelize.STRING, allowNull: false},
  14. });
  15.  
  16.  
  17. app.get("/create-signature", async (req, res) => {
  18.     res.setHeader("Content-Type", "application/json");
  19.  
  20.     try {
  21.         if(req.query["magic-word"].match("[^a-zA-Z0-9\-]")) {
  22.             throw "invalid";
  23.         } else {
  24.             let signature = crypto.createHash("sha1")
  25.                 .update(config.signature_secret + req.query["magic-word"])
  26.                 .digest()
  27.                 .toString("hex");
  28.  
  29.             res.send(JSON.stringify({
  30.                 "signature": signature
  31.             }));
  32.         }
  33.     } catch (e) {
  34.         res.send(JSON.stringify({
  35.             "signature": null
  36.         }));
  37.     }
  38. });
  39.  
  40.  
  41. app.get("/unlock-system", async (req, res) => {
  42.     res.setHeader("Content-Type", "application/json");
  43.  
  44.     try {
  45.         let signature = crypto.createHash("sha1")
  46.             .update(config.signature_secret + req.query["magic-word"])
  47.             .digest()
  48.             .toString("hex");
  49.  
  50.         if(signature != req.query["signature"]) {
  51.             throw "invalid";
  52.         }
  53.  
  54.         let word = await Word.findOne({
  55.             where: {
  56.                 "word": req.query["magic-word"]
  57.             }
  58.         });
  59.  
  60.         res.send(JSON.stringify({
  61.             "correct": word !== null
  62.         }));
  63.     } catch (e) {
  64.         res.send(JSON.stringify({
  65.             "correct": false
  66.         }));
  67.     }
  68. });
  69.  
  70.  
  71. app.listen(42000);
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