θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/components/Modals/Password/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function PasswordModal({ mode = "single" }) {
export function usePasswordModal() {
const [auth, setAuth] = useState({
loading: true,
required: false,
requiresAuth: false,
mode: "single",
});

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/pages/Login/index.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from "react";
import PasswordModal, { usePasswordModal } from "@/components/Modals/Password";
import { FullScreenLoader } from "@/components/Preloader";
import { Navigate } from "react-router-dom";
import paths from "@/utils/paths";

export default function Login() {
const { loading, mode } = usePasswordModal();
const { loading, requiresAuth, mode } = usePasswordModal();
if (loading) return <FullScreenLoader />;
if (requiresAuth === false) return <Navigate to={paths.home()} />;

return <PasswordModal mode={mode} />;
}
10 changes: 8 additions & 2 deletions server/endpoints/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ function systemEndpoints(app) {

app.post("/request-token", async (request, response) => {
try {
const bcrypt = require("bcrypt");

if (await SystemSettings.isMultiUserMode()) {
const { username, password } = reqBody(request);
const existingUser = await User.get({ username });
Expand All @@ -121,7 +123,6 @@ function systemEndpoints(app) {
return;
}

const bcrypt = require("bcrypt");
if (!bcrypt.compareSync(password, existingUser.password)) {
response.status(200).json({
user: null,
Expand Down Expand Up @@ -159,7 +160,12 @@ function systemEndpoints(app) {
return;
} else {
const { password } = reqBody(request);
if (password !== process.env.AUTH_TOKEN) {
if (
!bcrypt.compareSync(
password,
bcrypt.hashSync(process.env.AUTH_TOKEN, 10)
)
) {
response.status(401).json({
valid: false,
token: null,
Expand Down
3 changes: 2 additions & 1 deletion server/utils/middleware/validatedRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ async function validatedRequest(request, response, next) {
return;
}

const bcrypt = require("bcrypt");
const { p } = decodeJWT(token);
if (p !== process.env.AUTH_TOKEN) {
if (!bcrypt.compareSync(p, bcrypt.hashSync(process.env.AUTH_TOKEN, 10))) {
response.status(401).json({
error: "Invalid auth token found.",
});
Expand Down