chore:little fixes and formating and linting and patches
This commit is contained in:
@@ -4,7 +4,7 @@ import { encodeHexLowerCase } from '@oslojs/encoding';
|
||||
|
||||
export async function hashPassword(password: string): Promise<string> {
|
||||
return await hash(password, {
|
||||
memoryCost: 19456,
|
||||
memoryCost: 19_456,
|
||||
timeCost: 2,
|
||||
outputLen: 32,
|
||||
parallelism: 1,
|
||||
@@ -13,13 +13,13 @@ export async function hashPassword(password: string): Promise<string> {
|
||||
|
||||
export async function verifyPasswordHash(
|
||||
hash: string,
|
||||
password: string,
|
||||
password: string
|
||||
): Promise<boolean> {
|
||||
return await verify(hash, password);
|
||||
}
|
||||
|
||||
export async function verifyPasswordStrength(
|
||||
password: string,
|
||||
password: string
|
||||
): Promise<boolean> {
|
||||
if (password.length < 8 || password.length > 255) {
|
||||
return false;
|
||||
@@ -27,7 +27,7 @@ export async function verifyPasswordStrength(
|
||||
const hash = encodeHexLowerCase(sha1(new TextEncoder().encode(password)));
|
||||
const hashPrefix = hash.slice(0, 5);
|
||||
const response = await fetch(
|
||||
`https://api.pwnedpasswords.com/range/${hashPrefix}`,
|
||||
`https://api.pwnedpasswords.com/range/${hashPrefix}`
|
||||
);
|
||||
const data = await response.text();
|
||||
const items = data.split('\n');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import crypto from 'node:crypto';
|
||||
import { type Session, type User, db } from '@openpanel/db';
|
||||
import { db, type Session, type User } from '@openpanel/db';
|
||||
import { sha256 } from '@oslojs/crypto/sha2';
|
||||
import {
|
||||
encodeBase32LowerCaseNoPadding,
|
||||
@@ -15,7 +15,7 @@ export function generateSessionToken(): string {
|
||||
|
||||
export async function createSession(
|
||||
token: string,
|
||||
userId: string,
|
||||
userId: string
|
||||
): Promise<Session> {
|
||||
const sessionId = encodeHexLowerCase(sha256(new TextEncoder().encode(token)));
|
||||
const session: Session = {
|
||||
@@ -38,7 +38,7 @@ export const EMPTY_SESSION: SessionValidationResult = {
|
||||
};
|
||||
|
||||
export async function createDemoSession(
|
||||
userId: string,
|
||||
userId: string
|
||||
): Promise<SessionValidationResult> {
|
||||
const user = await db.user.findUniqueOrThrow({
|
||||
where: {
|
||||
@@ -66,7 +66,7 @@ export const decodeSessionToken = (token: string): string | null => {
|
||||
};
|
||||
|
||||
export async function validateSessionToken(
|
||||
token: string | null | undefined,
|
||||
token: string | null | undefined
|
||||
): Promise<SessionValidationResult> {
|
||||
if (process.env.DEMO_USER_ID) {
|
||||
return createDemoSession(process.env.DEMO_USER_ID);
|
||||
|
||||
Reference in New Issue
Block a user