Feat: Check Pwd with MD5 + Salt
MD5 加盐方式验证密码
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Api, Get, Query, useContext, useInject } from "@midwayjs/hooks";
|
||||
import { Context } from "@midwayjs/koa";
|
||||
import { RedisService } from "@midwayjs/redis";
|
||||
import { prisma } from "../utils/prisma";
|
||||
|
||||
@@ -8,7 +9,7 @@ export default Api(
|
||||
Get(),
|
||||
Query<{ play?: string }>(),
|
||||
async () => {
|
||||
const ctx = useContext();
|
||||
const ctx = useContext<Context>();
|
||||
const client = await useInject(RedisService);
|
||||
|
||||
// 设置 Header
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
import { Api, Get, Query, useContext, useInject } from "@midwayjs/hooks";
|
||||
import { Api, Get, Query, useContext, useInject, useConfig } from "@midwayjs/hooks";
|
||||
import { JwtService } from "@midwayjs/jwt";
|
||||
import { Context } from "@midwayjs/koa";
|
||||
import { prisma } from "../../utils/prisma";
|
||||
import md5 from "md5";
|
||||
|
||||
export default Api(
|
||||
Get(),
|
||||
Query<{ username: string, password: string }>(),
|
||||
async () => {
|
||||
const ctx = useContext();
|
||||
const ctx = useContext<Context>();
|
||||
const config = useConfig();
|
||||
|
||||
const jwt = await useInject(JwtService);
|
||||
|
||||
const pwd = md5(config.pwdSalt + ctx.query.password);
|
||||
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
name: ctx.query.username,
|
||||
password: ctx.query.password
|
||||
name: ctx.query.username as string,
|
||||
password: pwd
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ export default createConfiguration({
|
||||
},
|
||||
passport: {
|
||||
session: false
|
||||
}
|
||||
},
|
||||
pwdSalt: env.parsed ?. PAUL_PWD_SALT
|
||||
}
|
||||
}],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user