MCPcopy Create free account
hub / github.com/Effect-TS/effect / md5PasswordUnsafe

Function md5PasswordUnsafe

packages/sql/pg/src/PgAuth.ts:94–105  ·  view source on GitHub ↗
(options: {
  readonly user: string
  readonly password: string
  readonly salt: Uint8Array
})

Source from the content-addressed store, hash-verified

92 * @since 4.0.0
93 */
94const md5PasswordUnsafe = (options: {
95 readonly user: string
96 readonly password: string
97 readonly salt: Uint8Array
98}): string => {
99 if (options.salt.length !== 4) {
100 return fail(`PostgreSQL MD5 salt must be exactly 4 bytes, received ${options.salt.length}`)
101 }
102 const inner = createHash("md5").update(textEncoder.encode(options.password + options.user)).digest("hex")
103 const outer = createHash("md5").update(textEncoder.encode(inner)).update(options.salt).digest("hex")
104 return `md5${outer}`
105}
106
107/**
108 * Computes the legacy PostgreSQL MD5 password response.

Callers 1

md5PasswordFunction · 0.85

Calls 4

encodeMethod · 0.80
failFunction · 0.70
updateMethod · 0.65
digestMethod · 0.45

Tested by

no test coverage detected