backend/source/services/auth_internal.ts

74 lines
1.6 KiB
TypeScript
Raw Permalink Normal View History

2025-09-25 17:18:16 +02:00
/*
This file is part of »zeitbild«.
Copyright 2025 'kcf' <fenris@folksprak.org>
»zeitbild« is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
»zeitbild« is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with »zeitbild«. If not, see <http://www.gnu.org/licenses/>.
*/
2024-09-18 18:17:25 +02:00
namespace _zeitbild.service.auth_internal
{
/**
*/
export function set(
name : string,
password : string
) : Promise<void>
{
return (
lib_plankton.bcrypt.compute(password)
2024-09-19 13:34:07 +02:00
.then<boolean>(
2024-09-18 18:17:25 +02:00
(password_image) => _zeitbild.repository.auth_internal.write(name, password_image)
)
2024-09-19 13:34:07 +02:00
.then<void>(
() => Promise.resolve<void>(undefined)
)
);
}
/**
*/
export async function check_raw(
password_image : string,
password : string
) : Promise<boolean>
{
return lib_plankton.bcrypt.compare(
password_image,
password
2024-09-18 18:17:25 +02:00
);
}
/**
*/
export async function check(
name : string,
password : string
) : Promise<boolean>
{
try {
const password_image : string = await _zeitbild.repository.auth_internal.read(name);
2024-09-19 13:34:07 +02:00
return check_raw(password_image, password);
2024-09-18 18:17:25 +02:00
}
catch (error) {
return Promise.resolve<boolean>(false);
}
}
2024-09-19 13:34:07 +02:00
2024-09-18 18:17:25 +02:00
}