Feat: Check Pwd with MD5 + Salt

MD5 加盐方式验证密码
This commit is contained in:
2022-05-25 23:32:17 +08:00
parent 02e7d3ad5a
commit ba5e92e2be
6 changed files with 50 additions and 6 deletions
+2 -1
View File
@@ -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
+9 -4
View File
@@ -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
}
});
+2 -1
View File
@@ -30,7 +30,8 @@ export default createConfiguration({
},
passport: {
session: false
}
},
pwdSalt: env.parsed ?. PAUL_PWD_SALT
}
}],
});