1
0
Fork 0

wip(backend): Login flow

This commit is contained in:
joostdecock 2022-11-02 12:47:13 +01:00
parent f6a796959b
commit 553ab91d26
4 changed files with 168 additions and 24 deletions

View file

@ -1,7 +1,7 @@
import bcrypt from 'bcryptjs' // Required for legacy password hashes
import { createHash, createCipheriv, createDecipheriv, scryptSync, randomBytes } from 'crypto'
import { log } from './log.mjs'
import { asJson, clean } from './index.mjs'
import { asJson } from './index.mjs'
/*
* Hashes an email address (or other string)
@ -14,7 +14,7 @@ export const hash = (string) => createHash('sha256').update(string).digest('hex'
* This is not used in anything cryptographic. It is only used as a temporary
* username to avoid username collisions
*/
export const randomString = (bytes=8) => randomBytes(bytes).toString('hex')
export const randomString = (bytes = 8) => randomBytes(bytes).toString('hex')
/*
* Returns an object holding encrypt() and decrypt() methods

View file

@ -4,7 +4,8 @@ import { api } from '../config.mjs'
* Cleans a string (typically email) for hashing
*/
export const clean = (string) => {
if (typeof string !== 'string') throw 'clean() only takes a string as input'
if (typeof string === 'number') string = string.toString()
if (typeof string !== 'string') throw 'clean() only takes a string or number as input'
return string.toLowerCase().trim()
}