New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bcrypt-as-promised

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bcrypt-as-promised - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

30

index.js
'use strict';
var util = require('util');
var bcrypt = require('bcrypt');

@@ -12,10 +14,23 @@ var nodefn = require('when/node');

function MismatchError(message){
Error.call(this);
this.message = message;
this.name = MismatchError.name;
if(typeof Error.captureStackTrace === 'function'){
Error.captureStackTrace(this, MismatchError);
}
}
util.inherits(MismatchError, Error);
function throwOnInvalid(valid){
if(!valid){
return when.reject(new MismatchError('invalid'));
} else {
return valid;
}
}
function compare(password, hash){
return getValid(password, hash)
.then(function(valid){
if(!valid){
return when.reject(new Error('invalid'));
}
return valid;
});
.then(throwOnInvalid);
}

@@ -38,3 +53,4 @@

compare: compare,
getRounds: getRounds
getRounds: getRounds,
MISMATCH_ERROR: MismatchError
};
{
"name": "bcrypt-as-promised",
"version": "1.0.1",
"version": "1.1.0",
"description": "A promisified bcrypt",

@@ -8,3 +8,3 @@ "main": "index.js",

"test": "istanbul cover _mocha && npm run check-coverage",
"check-coverage": "istanbul check-coverage --statements 100 --branches 100 --lines 100 --functions 100"
"check-coverage": "istanbul check-coverage"
},

@@ -11,0 +11,0 @@ "repository": {

@@ -16,24 +16,34 @@ bcrypt-as-promised

hashing:
```javascript
bcrypt.hash('my password', 10)
.then(console.log, console.error)
```js
bcrypt.hash('my password', 10)
.then(console.log, console.error)
```
comparing:
(note that an invalid password/hash combo errors as a rejected promise)
```javascript
bcrypt.compare('my password', someHash)
.then(console.log, console.error)
```js
bcrypt.compare('my password', someHash)
.then(console.log, console.error)
```
__Note: an invalid password/hash combo errors as a rejected promise__
The rejection can be checked against `instanceof bcrypt.MISMATCH_ERROR`
```js
bcrypt.compare('invalid password', someHash)
.then(handleValidPassword)
.catch(bcrypt.MISMATCH_ERROR, handleInvalidPassword)
.catch(handleOtherErrors);
```
generating a salt:
```javascript
bcrypt.genSalt(10)
.then(console.log, console.error)
```js
bcrypt.genSalt(10)
.then(console.log, console.error)
```
calculating the rounds used in a salt:
```javascript
bcrypt.getRounds(someHash)
.then(console.log, console.error)
```js
bcrypt.getRounds(someHash)
.then(console.log, console.error)
```

@@ -53,2 +53,8 @@ 'use strict';

it('should error with MISMATCH_ERROR on an invalid password', function(){
var badPassword = 'a BAD password';
return expect(bcrypt.compare(badPassword, goodHash))
.to.eventually.be.rejectedWith(bcrypt.MISMATCH_ERROR);
});
it('should get number of rounds from a hash', function(){

@@ -55,0 +61,0 @@ return expect(bcrypt.getRounds(goodHash))

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc