16 lines
504 B
JavaScript
16 lines
504 B
JavaScript
import { createHmac } from "crypto";
|
|
import grabKeys from "../../utils/grab-keys";
|
|
/**
|
|
* # Hash password Function
|
|
*/
|
|
export default function hashPassword({ password, encryptionKey, }) {
|
|
const { key } = grabKeys({ encryptionKey });
|
|
if (!(key === null || key === void 0 ? void 0 : key.match(/.{8,}/))) {
|
|
throw new Error("Encryption key is invalid");
|
|
}
|
|
const hmac = createHmac("sha512", key);
|
|
hmac.update(password);
|
|
let hashed = hmac.digest("base64");
|
|
return hashed;
|
|
}
|