mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
969 B
45 lines
969 B
6 years ago
|
'use strict';
|
||
|
|
||
4 years ago
|
const { tripcodeSecret } = require(__dirname+'/../../configs/secrets.js')
|
||
5 years ago
|
, { createHash } = require('crypto')
|
||
4 years ago
|
, { encode } = require('iconv-lite')
|
||
|
, crypt = require('unix-crypt-td-js')
|
||
|
, replace = {
|
||
|
':': 'A',
|
||
|
';': 'B',
|
||
|
'<': 'C',
|
||
|
'=': 'D',
|
||
|
'>': 'E',
|
||
|
'?': 'F',
|
||
|
'@': 'G',
|
||
|
'[': 'a',
|
||
|
'\\': 'b',
|
||
|
']': 'c',
|
||
|
'^': 'd',
|
||
|
'_': 'e',
|
||
|
'`': 'f',
|
||
|
};
|
||
6 years ago
|
|
||
4 years ago
|
module.exports = {
|
||
6 years ago
|
|
||
4 years ago
|
getSecureTrip: async (password) => {
|
||
|
const tripcodeHash = createHash('sha256').update(password + tripcodeSecret).digest('base64');
|
||
|
const tripcode = tripcodeHash.substring(tripcodeHash.length-10);
|
||
|
return tripcode;
|
||
|
},
|
||
|
|
||
|
getInsecureTrip: (password) => {
|
||
4 years ago
|
const encoded = encode(password, 'SHIFT_JIS')
|
||
|
.toString('latin1');
|
||
4 years ago
|
let salt = `${encoded}H..`
|
||
|
.substring(1, 3)
|
||
|
.replace(/[^.-z]/g, '.');
|
||
|
for (let find in replace) {
|
||
|
salt = salt.split(find).join(replace[find]);
|
||
|
}
|
||
|
const hashed = crypt(encoded, salt);
|
||
|
return hashed.slice(-10);
|
||
|
},
|
||
6 years ago
|
|
||
|
}
|