interface Password { password : string ; validity : number ; } const PASSWORDS = new Map ( ) ; function _getAndClean ( user ) { const entry = PASSWORDS . get ( user ) ; if ( entry ) { if ( entry . validity > Date . now ( ) ) { return entry ; } PASSWORDS . delete ( user ) ; } return undefined ; } async function prosodyRegisterUser ( user ) { const entry = _getAndClean ( user ) ; const validity = Date . now ( ) + ( 24 * 60 * 60 * 1000 ) ; if ( entry ) { entry . validity = validity ; return entry . password ; } const password = Math . random ( ) . toString ( 36 ) . slice ( 2 , 12 ) + Math . random ( ) . toString ( 36 ) . slice ( 2 , 12 ) ; PASSWORDS . set ( user , { password : password , validity : validity } ) ; return password ; } async function prosodyUserRegistered ( user ) { const entry = _getAndClean ( user ) ; return ! ! entry ; } async function prosodyCheckUserPassword ( user , password ) { const entry = _getAndClean ( user ) ; if ( entry && entry . password === password ) { return true ; } return false ; } export { prosodyRegisterUser , prosodyUserRegistered , prosodyCheckUserPassword } ;