mirror of https://gitgud.io/fatchan/jschan.git
parent
39b6999c9e
commit
a73a560011
4 changed files with 48 additions and 27 deletions
@ -1,27 +0,0 @@ |
|||||||
|
|
||||||
'use strict'; |
|
||||||
|
|
||||||
const Mongo = require(__dirname+'/../helpers/db.js') |
|
||||||
, db = Mongo.client.db('captcha'); |
|
||||||
|
|
||||||
module.exports = { |
|
||||||
|
|
||||||
db, |
|
||||||
|
|
||||||
findOne: async (name) => { |
|
||||||
return db.collection('captcha').findOne({ '_id': name }); |
|
||||||
}, |
|
||||||
|
|
||||||
insertOne: async (data) => { |
|
||||||
return db.collection('captcha').insertOne(data); |
|
||||||
}, |
|
||||||
|
|
||||||
deleteOne: async (data) => { |
|
||||||
return db.collection('captcha').deleteOne(data); |
|
||||||
}, |
|
||||||
|
|
||||||
deleteAll: async () => { |
|
||||||
return db.collection('captcha').deleteMany({}); |
|
||||||
}, |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,21 @@ |
|||||||
|
|
||||||
|
'use strict'; |
||||||
|
|
||||||
|
const Mongo = require(__dirname+'/../helpers/db.js') |
||||||
|
, db = Mongo.client.db('tripcodes').collection('tripcodes'); |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
|
||||||
|
findOne: (password) => { |
||||||
|
return db.findOne({ '_id': password }); |
||||||
|
}, |
||||||
|
|
||||||
|
insertOne: (password, trip) => { |
||||||
|
return db.insertOne({ '_id': password, 'code': trip }); |
||||||
|
}, |
||||||
|
|
||||||
|
deleteAll: () => { |
||||||
|
return db.deleteMany({}); |
||||||
|
}, |
||||||
|
|
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
module.exports = (hex) => { |
||||||
|
const r = parseInt(hex.substr(0,2), 16); |
||||||
|
const g = parseInt(hex.substr(2,2), 16); |
||||||
|
const b = parseInt(hex.substr(4,2), 16) |
||||||
|
return 0.375 * r + 0.5 * g + 0.125 * b; |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
const Tripcodes = require(__dirname+'/../db-models/trips.js') |
||||||
|
, crypto = require('crypto'); |
||||||
|
|
||||||
|
module.exports = async (password) => { |
||||||
|
|
||||||
|
//return existing trip if exists
|
||||||
|
let existing = await Tripcodes.findOne(password); |
||||||
|
if (existing) { |
||||||
|
return existing.code; |
||||||
|
} |
||||||
|
|
||||||
|
//same as lynxchan does it, but i dont think this is secure. welcome to change.
|
||||||
|
const trip = crypto.createHash('sha256').update(password + Math.random()).digest('base64').substring(0, 6); |
||||||
|
await Tripcodes.insertOne(password, trip); |
||||||
|
return trip; |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue