Skip to content

Commit

Permalink
perf: hash password for login
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Aug 6, 2023
1 parent 7d8a036 commit ff71f26
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -71,6 +71,7 @@
"remark-gfm": "^3.0.1",
"remark-math": "^5.1.1",
"seemly": "^0.3.6",
"sha-anything": "^0.0.4",
"solid-contextmenu": "0.0.2",
"solid-icons": "^1.0.1",
"solid-js": "^1.4.8",
Expand Down
26 changes: 26 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/pages/login/index.tsx
Expand Up @@ -20,6 +20,7 @@ import {
notify,
handleRespWithoutNotify,
base_path,
hashPwd,
} from "~/utils"
import { Resp } from "~/types"
import LoginBg from "./LoginBg"
Expand All @@ -45,10 +46,10 @@ const Login = () => {
const [opt, setOpt] = createSignal("")
const [remember, setRemember] = createStorageSignal("remember-pwd", "false")
const [loading, data] = useFetch(
(): Promise<Resp<{ token: string }>> =>
r.post("/auth/login", {
async (): Promise<Resp<{ token: string }>> =>
r.post("/auth/login/hash", {
username: username(),
password: password(),
password: await hashPwd(password()),
otp_code: opt(),
}),
)
Expand Down
7 changes: 7 additions & 0 deletions src/utils/hash.ts
@@ -0,0 +1,7 @@
import { sha256 } from "sha-anything"

const hash_salt = "https://github.com/alist-org/alist"

export async function hashPwd(pwd: string) {
return await sha256(`${pwd}-${hash_salt}`)
}
1 change: 1 addition & 0 deletions src/utils/index.ts
Expand Up @@ -9,3 +9,4 @@ export * from "./str"
export * from "./handle_resp"
export * from "./const"
export * from "./api"
export * from "./hash"

0 comments on commit ff71f26

Please sign in to comment.