backend/source/services/auth_internal.ts

55 lines
895 B
TypeScript
Raw Normal View History

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
}