remove jssha and add bcrypt for password hashing with salt

This commit is contained in:
2025-08-21 10:52:29 +02:00
parent 723ec0773d
commit ec15095da3
6 changed files with 48 additions and 21 deletions

View File

@@ -45,8 +45,7 @@
}
const URL = '/api/users';
const hashedUserPassword = new jsSHA('SHA-512', 'TEXT').update(userPassword).getHash('HEX');
const userData = { userName: userName, userPassword: hashedUserPassword };
const userData = { userName: userName, userPassword: userPassword };
try {
const response = await fetch(URL, {

View File

@@ -1,5 +1,8 @@
import { json } from '@sveltejs/kit';
import { addUser, getUsers } from '$lib/server/userService';
import bcrypt from 'bcrypt';
const saltRounds = 12;
export function GET({ locals }) {
if (!locals.user) {
@@ -24,7 +27,8 @@ export async function POST({ request, locals }) {
return json({ error: 'Missing input' }, { status: 400 });
}
const rowInfo = addUser(userName, userPassword);
const hashedPassword = bcrypt.hashSync(userPassword, saltRounds);
const rowInfo = addUser(userName, hashedPassword);
if (rowInfo?.changes == 1) {
return json({ userId: rowInfo.lastInsertRowid, userName: userName }, { status: 201 });