Use crypto module for token generation

This commit is contained in:
Shane Kilkelly 2017-10-12 11:36:45 +01:00
parent 22c5f41fb6
commit 6feedf5520

View file

@ -1,12 +1,12 @@
crypto = require 'crypto'
module.exports = ProjectTokenGenerator = module.exports = ProjectTokenGenerator =
readOnlyToken: () -> readOnlyToken: () ->
length = 12 length = 12
tokenAlpha = 'bcdfghjkmnpqrstvwxyz' tokenAlpha = 'bcdfghjkmnpqrstvwxyz'
result = '' result = ''
for _n in [1..length] crypto.randomBytes(length).map( (a) -> result += tokenAlpha[a % tokenAlpha.length] )
i = Math.floor(Math.floor(Math.random() * tokenAlpha.length))
result += tokenAlpha[i]
return result return result
readAndWriteToken: () -> readAndWriteToken: () ->