.then( () => { return credential() .hash(body.password) .then(hash => axios.post(USERS_CLASSES_URL, {...body, password: hash})) .then(resp => res .set('Location', '/me') .json(201, {_id: resp.data._id, token: jwt.sign({id: resp.data._id}, SECRET_JWT)})) })
.then(resp => { const [doc] = resp.data; if(doc === undefined){res.send(401)} return credential() .verify(doc.password, password) .then( (isValid) => { delete doc.password; return isValid ? res.json(201, {...doc, token: jwt.sign({id: doc._id}, SECRET_JWT)}) : res.send(401) }) })
const credential = require('credential') const pw = credential({ work: 0.1 }) module.exports = { async get (pass) { const hash = await pw.hash(pass) return new Buffer(hash).toString('base64') }, async verify (hashObjectBase64, inputPassword) { const unbased = new Buffer(hashObjectBase64, 'base64').toString('ascii') return await pw.verify(unbased, inputPassword) } }
'use strict' const path = require('path') const low = require('lowdb') const express = require('express') const credential = require('credential') const bodyParser = require('body-parser') const storage = require('lowdb/file-async') const pw = credential() const jsonParser = bodyParser.json() class CMS { constructor (app, database) { this.app = app this.data = low(database || 'data.json', {storage}) this.users = low('users.json', {storage}) this.authed = {} this.timeout = 180000 } /* check if user has a valid login */ checkLogin (req, res, redirect) { const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress if (this.authed[ip]) { if (Date.now() >= this.authed[ip].time) { delete this.authed[ip] return false }
self.initializeCredential = function() { self.pw = credential(); };
const setToTestMode = () => { pw = credential({work: 0}); }
'use strict'; const credential = require('credential'); let pw = credential(); const db = require('./db'); /** * If we test the application, sometimes calculating the credentials is too much. * This function lessens the work burden. */ const setToTestMode = () => { pw = credential({work: 0}); } const encryptPassword = (password, cb) => { pw.hash(password, function (err, hash) { cb(err, hash); }); }; const verifyPassword = (storedPasswordHash, cleartextPassword, cb) => { pw.verify(storedPasswordHash, cleartextPassword, function (err, isValid) { cb(err, isValid); }); }; const findByUsername = (username, cb) => { db.connect((err, client, done) => { client.query('select * from localuser where name=$1', [username], (err, result) => { done();