mirror of
https://github.com/Nezumi-2711/next-gdrive-index.git
synced 2026-09-22 20:01:36 +00:00
Change site password using sha256 hash
This commit is contained in:
@@ -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
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user