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

19 lines
471 B
TypeScript
Raw Normal View History

import env from "../environment"
const bcrypt = env.JS_BCRYPT ? require("bcryptjs") : require("bcrypt")
import { v4 } from "uuid"
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)
}
2021-04-19 12:34:07 +02:00
export function newid() {
2021-04-19 12:34:07 +02:00
return v4().replace(/-/g, "")
}