how to make a product key for your node js application

Solutions on MaxInterview for how to make a product key for your node js application by the best coders in the world

showing results for - "how to make a product key for your node js application"
Caterina
05 Jan 2019
1/*
2    This code comes from Vincent Lab
3    And it has a video version linked here: https://www.youtube.com/watch?v=fQk5WqpoRNQ
4*/
5
6// Import dependencies
7const jwt = require("jsonwebtoken");
8const Cryptr = require("cryptr");
9
10// Secrets
11const secret1 = "123";
12const secret2 = "123";
13
14// Cryptr
15const cryptr = new Cryptr(secret1);
16
17// Generate the product key
18function generate(type) {
19    return cryptr.encrypt(jwt.sign({ type: type }, secret2));
20}
21
22// Validate the product key
23function validate(productKey) {
24    return jwt.verify(cryptr.decrypt(productKey), secret2);
25}
26
27// Examples
28console.log(validate(generate("basic")));
29console.log(generate("premium"));