budibase/packages/backend-core/src/utils/hashing.ts

16 lines
417 B
TypeScript
Raw Normal View History

import env from "../environment"
2023-11-20 21:52:29 +01:00
export * from "../docIds/newid"
const bcrypt = env.JS_BCRYPT ? require("bcryptjs") : require("bcrypt")
2021-04-07 12:33:16 +02:00
const SALT_ROUNDS = env.SALT_ROUNDS || 10
2021-04-07 12:33:16 +02:00
export async function hash(data: string) {
2021-04-07 12:33:16 +02:00
const salt = await bcrypt.genSalt(SALT_ROUNDS)
return bcrypt.hash(data, salt)
}
export async function compare(data: string, encrypted: string) {
2021-04-07 12:33:16 +02:00
return bcrypt.compare(data, encrypted)
}