feat: hash passwords

This commit is contained in:
eneller
2026-07-23 11:23:53 +02:00
parent ceab2dee0a
commit a3158894c8
6 changed files with 65 additions and 10 deletions

View File

@@ -15,9 +15,12 @@
"setup": "docker compose up -d",
"teardown": "docker compose down",
"keygen": "ts-node src/scripts/keygen.ts",
"hash": "ts-node src/scripts/hash.ts",
"verify": "ts-node src/scripts/verify.ts",
"dev": "npm run setup && npm run node; npm run teardown"
},
"dependencies": {
"bcrypt": "^6.0.0",
"cookie-parser": "^1.4.7",
"cors": "^2.8.6",
"dotenv": "^17.3.1",
@@ -31,6 +34,7 @@
"winston": "^3.19.0"
},
"devDependencies": {
"@types/bcrypt": "^6.0.0",
"@types/cookie-parser": "^1.4.10",
"@types/cors": "^2.8.19",
"@types/express": "^5.0.6",

View File

@@ -1,3 +1,4 @@
import { compare } from 'bcrypt';
import express from 'express';
import { logger } from '../util/logging';
import User from '../model/user';
@@ -12,9 +13,7 @@ router.post('/login', async (req, res) => {
const data : LoginRequest = req.body;
const user = await User.findOne({where: { userID: data.username}});
if (!user) return res.status(401).json(new Msg('Invalid credentials'));
const isMatch = (data.password == user.password);
//TODO hash passwords
//const isMatch = await bcrypt.compare(password, user.passwordHash);
const isMatch = await compare(data.password, user.password);
if (!isMatch) return res.status(401).json(new Msg('Invalid credentials'));
// successfully authenticated

View File

@@ -0,0 +1,5 @@
import {hash} from 'bcrypt';
let pass = process.argv[2];
hash(pass, 10, function(err, hash) {
console.log(hash);
});

View File

@@ -0,0 +1,6 @@
import {compare} from 'bcrypt';
let pass = process.argv[2];
let hash = process.argv[3];
compare(pass,hash, function(err, result){
console.log(result);
});