use xxhash
This commit is contained in:
parent
5c29ebd821
commit
6ec575810a
5 changed files with 42 additions and 26 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
package-lock.json
|
package-lock.json
|
||||||
.env
|
.env
|
||||||
|
yarn.lock
|
|
@ -4,7 +4,9 @@
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node src/index.js"
|
"start": "node src/index.js",
|
||||||
|
"adduser": "python script/adduser.py",
|
||||||
|
"build": "babel src -d lib"
|
||||||
},
|
},
|
||||||
"author": "unurled",
|
"author": "unurled",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
@ -16,7 +18,8 @@
|
||||||
"mongoose": "^6.1.8",
|
"mongoose": "^6.1.8",
|
||||||
"passport": "^0.5.2",
|
"passport": "^0.5.2",
|
||||||
"passport-gitlab2": "^5.0.0",
|
"passport-gitlab2": "^5.0.0",
|
||||||
"passport-local": "^1.0.0"
|
"passport-local": "^1.0.0",
|
||||||
|
"xxhashjs": "^0.2.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tailwindcss": "^3.0.16"
|
"tailwindcss": "^3.0.16"
|
||||||
|
|
24
script/adduser.py
Normal file
24
script/adduser.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import collections
|
||||||
|
from pymongo import MongoClient
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from os import getenv
|
||||||
|
import xxhash
|
||||||
|
import getpass
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
client=MongoClient(getenv("MONGO"))
|
||||||
|
db = client.get_database(getenv("DB"))
|
||||||
|
|
||||||
|
def add_user():
|
||||||
|
username = input('username ? ')
|
||||||
|
password = getpass.getpass('password ? ')
|
||||||
|
pass_retry = getpass.getpass('Re-type your password ? ')
|
||||||
|
if password != pass_retry:
|
||||||
|
print("not correct password.")
|
||||||
|
add_user()
|
||||||
|
hashed_pass = xxhash.xxh64(password, 5).hexdigest()
|
||||||
|
collection = db["users"]
|
||||||
|
print(f"username: {username}, password: {hashed_pass}")
|
||||||
|
collection.update_one({ "name": username}, { "$set": {"pass": hashed_pass}})
|
||||||
|
|
||||||
|
add_user()
|
16
src/login.js
16
src/login.js
|
@ -2,23 +2,11 @@ const User = require('./model/user');
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
const XXH = require('xxhashjs');
|
||||||
const cyrb53 = function(str, seed = 0) {
|
|
||||||
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
|
||||||
for (let i = 0, ch; i < str.length; i++) {
|
|
||||||
ch = str.charCodeAt(i);
|
|
||||||
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
||||||
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
||||||
}
|
|
||||||
h1 = Math.imul(h1 ^ (h1>>>16), 2246822507) ^ Math.imul(h2 ^ (h2>>>13), 3266489909);
|
|
||||||
h2 = Math.imul(h2 ^ (h2>>>16), 2246822507) ^ Math.imul(h1 ^ (h1>>>13), 3266489909);
|
|
||||||
return 4294967296 * (2097151 & h2) + (h1>>>0);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
router.post('/auth', function(request, response) {
|
router.post('/auth', function(request, response) {
|
||||||
var username = request.body.username;
|
var username = request.body.username;
|
||||||
var password = cyrb53(request.body.password, 5).toString();
|
var password = XXH.h64(request.body.password, 5).toString(16);
|
||||||
if (username && password) {
|
if (username && password) {
|
||||||
let user = User.findOne({
|
let user = User.findOne({
|
||||||
name: username, pass: password
|
name: username, pass: password
|
||||||
|
|
18
src/text.js
18
src/text.js
|
@ -1,21 +1,21 @@
|
||||||
|
require('dotenv').config()
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
const User = require('./model/user');
|
const User = require('./model/user');
|
||||||
|
|
||||||
router.get('/', function(request, response) {
|
router.get('/', function(request, response) {
|
||||||
let username = 'unurled';
|
let username = "";
|
||||||
console.log(username)
|
console.log(username);
|
||||||
let user = User.findOne(
|
User.find({}, function(err, res) {
|
||||||
{user: username}, function(err, results) {
|
console.log("updated, ")
|
||||||
console.log("updated, ")
|
console.log(res[0].text)
|
||||||
console.log(results.text)
|
if (res[0].text.length > 0) {
|
||||||
if (results.text.length > 0) {
|
response.send('{"text": "' + res[0].text + '"}')
|
||||||
response.send('{"text": "' + results.text + '"}')
|
|
||||||
//response.sendFile(path.join(__dirname + `/public/index.html`))
|
//response.sendFile(path.join(__dirname + `/public/index.html`))
|
||||||
} else {
|
} else {
|
||||||
response.send('Incorrect Username and/or Password!');
|
response.send('Incorrect Username and/or Password!');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue