Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/graphql / src / deps / fromPasswordToHashed.ts
Size: Mime:
// @todo in another file
import { createHash } from 'crypto'

const create = algorithm => async (buffer, opts = {}) => {
  const options = Object.assign(
    {
      outputFormat: 'hex',
    },
    opts
  )

  const hash = createHash(algorithm)
  hash.update(buffer, typeof buffer === 'string' ? 'utf8' : undefined)

  if (options.outputFormat === 'hex') {
    return hash.digest('hex')
  }

  return hash.digest().buffer
}

// @todo use a better sha @@security
const sha512 = create('sha512')

async function toPassword(password: string) {
  if (process.env.SKAVA123) {
    return 'Skava@123'
  } else {
    const hashed = await sha512(password || '@@empty')
    // @todo just check if it contains a number and aZ cool
    return hashed.slice(0, 27) + '@1aZ'
  }
}

export { toPassword }