WIP token

This commit is contained in:
newtbot
2024-01-16 04:43:39 +08:00
parent 290d0653d9
commit 7e4b2d8026
19 changed files with 534 additions and 77 deletions

View File

@ -0,0 +1,30 @@
const { sequelize } = require("../database/mySql.js");
const { apikeyModel } = require("../database/model/apikeyModel.js");
const { userModel } = require("../database/model/userModel.js");
const { Op, Sequelize } = require("sequelize");
async function getUser() {
const user = await userModel.findAll();
return user;
}
async function addUser(user) {
//console.log(user);
await userModel.create(user);
}
async function getAPIKey() {
const apikey = await apikeyModel.findAll();
return apikey;
}
async function addAPIKey(apikey) {
await apikeyModel.create(apikey);
}
module.exports = {
getUser,
addUser,
getAPIKey,
addAPIKey,
};

View File

@ -0,0 +1,37 @@
const bcrypt = require('bcrypt');
const saltRounds = 10;
//https://github.com/kelektiv/node.bcrypt.js#readme
/*
// Load hash from your password DB.
bcrypt.compare(myPlaintextPassword, hash, function(err, result) {
// result == true
});
bcrypt.compare(someOtherPlaintextPassword, hash, function(err, result) {
// result == false
});
*/
/*
//hash with salt
bcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) {
// Store hash in your password DB.
});
*/
async function hashPassword(password) {
return await bcrypt.hash(password, saltRounds);
}
async function hashAPIKey(apikey) {
return await bcrypt.hash(apikey, saltRounds);
}
module.exports = {
hashPassword,
hashAPIKey,
};

View File

@ -0,0 +1,17 @@
/*
const crypto = require('crypto');
Calling the UUID method returns a UUID of standard length that you can use in your program.
let uuid = crypto.randomUUID();
console.log(uuid);
*/
const crypto = require('crypto');
async function generateUUID() {
let uuid = crypto.randomUUID();
return uuid;
}
module.exports = { generateUUID };