basic-auth
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -0,1 +1,6 @@ | ||
2.0.1 / 2018-09-19 | ||
================== | ||
* deps: safe-buffer@5.1.2 | ||
2.0.0 / 2017-09-12 | ||
@@ -2,0 +7,0 @@ ================== |
{ | ||
"name": "basic-auth", | ||
"description": "node.js basic auth parser", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"license": "MIT", | ||
@@ -14,14 +14,14 @@ "keywords": [ | ||
"dependencies": { | ||
"safe-buffer": "5.1.1" | ||
"safe-buffer": "5.1.2" | ||
}, | ||
"devDependencies": { | ||
"eslint": "3.19.0", | ||
"eslint-config-standard": "10.2.1", | ||
"eslint-plugin-import": "2.7.0", | ||
"eslint": "5.6.0", | ||
"eslint-config-standard": "12.0.0", | ||
"eslint-plugin-import": "2.14.0", | ||
"eslint-plugin-markdown": "1.0.0-beta.6", | ||
"eslint-plugin-node": "5.1.1", | ||
"eslint-plugin-promise": "3.5.0", | ||
"eslint-plugin-standard": "3.0.1", | ||
"eslint-plugin-node": "7.0.1", | ||
"eslint-plugin-promise": "4.0.1", | ||
"eslint-plugin-standard": "4.0.0", | ||
"istanbul": "0.4.5", | ||
"mocha": "2.5.3" | ||
"mocha": "5.2.0" | ||
}, | ||
@@ -28,0 +28,0 @@ "files": [ |
@@ -68,2 +68,3 @@ # basic-auth | ||
var auth = require('basic-auth') | ||
var compare = require('tsscmp') | ||
@@ -74,3 +75,5 @@ // Create server | ||
if (!credentials || credentials.name !== 'john' || credentials.pass !== 'secret') { | ||
// Check credentials | ||
// The "check" function will typically be against your user store | ||
if (!credentials || !check(credentials.name, credentials.pass)) { | ||
res.statusCode = 401 | ||
@@ -84,2 +87,13 @@ res.setHeader('WWW-Authenticate', 'Basic realm="example"') | ||
// Basic function to validate credentials for example | ||
function check (name, pass) { | ||
var valid = true | ||
// Simple method to prevent short-circut and use timing-safe compare | ||
valid = compare(name, 'john') && valid | ||
valid = compare(pass, 'secret') && valid | ||
return valid | ||
} | ||
// Listen | ||
@@ -93,11 +107,11 @@ server.listen(3000) | ||
[npm-image]: https://img.shields.io/npm/v/basic-auth.svg | ||
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/basic-auth/master | ||
[coveralls-url]: https://coveralls.io/r/jshttp/basic-auth?branch=master | ||
[downloads-image]: https://badgen.net/npm/dm/basic-auth | ||
[downloads-url]: https://npmjs.org/package/basic-auth | ||
[node-version-image]: https://badgen.net/npm/node/basic-auth | ||
[node-version-url]: https://nodejs.org/en/download | ||
[npm-image]: https://badgen.net/npm/v/basic-auth | ||
[npm-url]: https://npmjs.org/package/basic-auth | ||
[node-version-image]: https://img.shields.io/node/v/basic-auth.svg | ||
[node-version-url]: https://nodejs.org/en/download | ||
[travis-image]: https://img.shields.io/travis/jshttp/basic-auth/master.svg | ||
[travis-image]: https://badgen.net/travis/jshttp/basic-auth/master | ||
[travis-url]: https://travis-ci.org/jshttp/basic-auth | ||
[coveralls-image]: https://img.shields.io/coveralls/jshttp/basic-auth/master.svg | ||
[coveralls-url]: https://coveralls.io/r/jshttp/basic-auth?branch=master | ||
[downloads-image]: https://img.shields.io/npm/dm/basic-auth.svg | ||
[downloads-url]: https://npmjs.org/package/basic-auth |
8895
114
+ Addedsafe-buffer@5.1.2(transitive)
- Removedsafe-buffer@5.1.1(transitive)
Updatedsafe-buffer@5.1.2