overleaf/services/web/app/coffee/Features/Project/ProjectTokenGenerator.coffee

16 lines
417 B
CoffeeScript
Raw Normal View History

2017-10-12 06:36:45 -04:00
crypto = require 'crypto'
module.exports = ProjectTokenGenerator =
readOnlyToken: () ->
length = 12
tokenAlpha = 'bcdfghjkmnpqrstvwxyz'
result = ''
2017-10-12 06:36:45 -04:00
crypto.randomBytes(length).map( (a) -> result += tokenAlpha[a % tokenAlpha.length] )
return result
readAndWriteToken: () ->
numerics = Math.random().toString().slice(2, 12)
token = ProjectTokenGenerator.readOnlyToken()
return "#{numerics}#{token}"