mirror of https://github.com/kern/filepizza
Use XKCD-style passphrases.
parent
9679dea646
commit
d8cb491402
@ -0,0 +1,2 @@
|
|||||||
|
require('babel/register')
|
||||||
|
module.exports = require('./lib/server')
|
||||||
@ -1,45 +1,39 @@
|
|||||||
import bases from 'bases'
|
import bases from 'bases'
|
||||||
import crypto from 'crypto'
|
import crypto from 'crypto'
|
||||||
|
import xkcdPassword from 'xkcd-password'
|
||||||
|
|
||||||
var tokenLength = 8
|
const TOKEN_OPTIONS = {
|
||||||
var tokens = {}
|
numWords: 4,
|
||||||
|
minLength: 4,
|
||||||
exports.create = function (socket) {
|
maxLength: 8
|
||||||
|
}
|
||||||
var maxNum = Math.pow(62, tokenLength)
|
|
||||||
var numBytes = Math.ceil(Math.log(maxNum) / Math.log(256))
|
|
||||||
|
|
||||||
var token = ''
|
var tokenGenerator = new xkcdPassword()
|
||||||
do {
|
var tokens = {}
|
||||||
do {
|
|
||||||
var bytes = crypto.randomBytes(numBytes)
|
|
||||||
var num = 0
|
|
||||||
for (var i = 0; i < bytes.length; i++) {
|
|
||||||
num += Math.pow(256, i) * bytes[i]
|
|
||||||
}
|
|
||||||
} while (num >= maxNum)
|
|
||||||
|
|
||||||
token = bases.toBase62(num)
|
export function create(socket) {
|
||||||
} while (token in tokens)
|
|
||||||
|
|
||||||
const result = {
|
return tokenGenerator.generate(TOKEN_OPTIONS).then((parts) => {
|
||||||
token: token,
|
const token = parts.join('-')
|
||||||
socket: socket
|
let result = {
|
||||||
}
|
token: token,
|
||||||
|
socket: socket
|
||||||
|
}
|
||||||
|
|
||||||
tokens[token] = result
|
tokens[token] = result
|
||||||
return result
|
return result
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.exists = function (token) {
|
export function exists(token) {
|
||||||
return token in tokens
|
return token in tokens
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.find = function (token) {
|
export function find(token) {
|
||||||
return tokens[token]
|
return tokens[token]
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.remove = function (client) {
|
export function remove(client) {
|
||||||
delete tokens[client.token]
|
delete tokens[client.token]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue