remove jssha and add bcrypt for password hashing with salt
This commit is contained in:
@@ -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, {
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user