
namespace _zeitbild.service.auth_internal
{
	
	/**
	 */
	export function set(
		name : string,
		password : string
	) : Promise<void>
	{
		return (
			lib_plankton.bcrypt.compute(password)
			.then<boolean>(
				(password_image) => _zeitbild.repository.auth_internal.write(name, password_image)
			)
			.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
		);
	}
	
	
	/**
	 */
	export async function check(
		name : string,
		password : string
	) : Promise<boolean>
	{
		try {
			const password_image : string = await _zeitbild.repository.auth_internal.read(name);
			return check_raw(password_image, password);
		}
		catch (error) {
			return Promise.resolve<boolean>(false);
		}
	}
	
}
