Change site password using sha256 hash

This commit is contained in:
mbaharip
2023-05-07 17:58:21 +07:00
parent 89a73e7bc9
commit d1e1e7e104
2 changed files with 12 additions and 15 deletions
+5 -3
View File
@@ -10,10 +10,12 @@ const config = {
// Fav icon of the site
// Also used as the logo of the site on the navbar
siteIcon: "/favicon.svg",
//
privateIndex: false,
// Add site page password protection
// If this is set, the site will be protected with the password
// NOTE: The files are still accessible via direct link, but the site is not.
privateIndex: true,
indexPassword:
"ac0f794f72d4366a57a2a4122ce04321:8b2f087de80d0d7faa89b5372df51268",
"640e3e38dd31aec254f214ba38541a82ddb615e73ce9c6129f33ef549b154ab9",
// Navbar menu links
navbarLinks: [
{
+7 -12
View File
@@ -19,7 +19,7 @@ import { LayoutContext } from "context/layoutContext";
import { ThemeContext } from "context/themeContext";
import fetcher from "utils/swrFetch";
import siteConfig from "config/site.config";
import { decrypt, encrypt } from "utils/encryptionHelper";
import { hashToken, verifyHash } from "utils/hashHelper";
const exo2 = Exo_2({
weight: ["300", "400", "600", "700"],
@@ -57,14 +57,8 @@ export default function App({ Component, pageProps }: AppProps) {
const adminPassword = localStorage.getItem("sitePassword");
if (siteConfig.privateIndex) {
const sitePassword = decrypt(siteConfig.indexPassword);
if (adminPassword) {
const decryptedPassword = decrypt(adminPassword);
if (decryptedPassword === sitePassword) {
setIsUnlocked(true);
} else {
setIsUnlocked(false);
}
if (adminPassword === siteConfig.indexPassword) {
setIsUnlocked(true);
} else {
setIsUnlocked(false);
}
@@ -205,15 +199,16 @@ export default function App({ Component, pageProps }: AppProps) {
<form
onSubmit={(e) => {
e.preventDefault();
const sitePassword = decrypt(
const verify = verifyHash(
passwordInput,
siteConfig.indexPassword,
);
if (passwordInput === sitePassword) {
if (verify) {
toast("Welcome back!");
setIsUnlocked(true);
localStorage.setItem(
"sitePassword",
encrypt(passwordInput),
hashToken(passwordInput),
);
setPasswordInput("");
} else {