(refactor) use sha256 instead of md5 for the test version password

This commit is contained in:
Valentyne Stigloher 2025-04-22 15:59:58 +02:00
parent d0b884c527
commit 0c444ad1af

View File

@ -1,6 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import sorter from 'avris-sorter'; import sorter from 'avris-sorter';
import md5 from 'js-md5';
import { useCookie } from 'nuxt/app'; import { useCookie } from 'nuxt/app';
import useConfig from '~/composables/useConfig.ts'; import useConfig from '~/composables/useConfig.ts';
@ -8,11 +7,11 @@ import useDark from '~/composables/useDark.ts';
import useDialogue from '~/composables/useDialogue.ts'; import useDialogue from '~/composables/useDialogue.ts';
import { longtimeCookieSetting } from '~/src/cookieSettings.ts'; import { longtimeCookieSetting } from '~/src/cookieSettings.ts';
import { LoadScriptError } from '~/src/errors.ts'; import { LoadScriptError } from '~/src/errors.ts';
import { executeUnlessPrerendering } from '~/src/helpers.ts'; import { executeUnlessPrerendering, sha256 } from '~/src/helpers.ts';
import { useMainStore } from '~/store/index.ts'; import { useMainStore } from '~/store/index.ts';
// no need to be super secure, just a sign that the page is not public // no need to be super secure, just a sign that the page is not public
const TESTER_PASSWORD_HASH = '82feeb96d60170e714df8fb062301e90'; const TESTER_PASSWORD_HASH = '3754c03824c4ea3b13e7b4b2d7ad35992dbf64f9ee680493fc7093bf176f49e5';
declare global { declare global {
interface Window { interface Window {
@ -35,8 +34,12 @@ const requiresLogin = computed((): boolean => {
return !config.macrolanguage?.enabled && (runtimeConfig.public.env === 'test' || return !config.macrolanguage?.enabled && (runtimeConfig.public.env === 'test' ||
config.locale !== '_' && !locales[config.locale]?.published); config.locale !== '_' && !locales[config.locale]?.published);
}); });
const testerPasswordValid = computed((): boolean => { const testerPasswordValid = ref<boolean | undefined>();
return !!testerPasswordCookie.value && md5(testerPasswordCookie.value) === TESTER_PASSWORD_HASH; watchEffect(async () => {
testerPasswordValid.value = undefined;
if (testerPasswordCookie.value) {
testerPasswordValid.value = await sha256(testerPasswordCookie.value) === TESTER_PASSWORD_HASH;
}
}); });
const checkTesterPassword = (): void => { const checkTesterPassword = (): void => {
testerPasswordCookie.value = testerPassword.value; testerPasswordCookie.value = testerPassword.value;
@ -123,7 +126,7 @@ const loadAds = async (): Promise<void> => {
Sign in Sign in
</button> </button>
</div> </div>
<p v-if="testerPasswordCookie && !testerPasswordValid" class="small text-danger"> <p v-if="testerPasswordCookie && testerPasswordValid === false" class="small text-danger">
<Icon v="exclamation-triangle" /> <Icon v="exclamation-triangle" />
Password invalid Password invalid
</p> </p>