@adonisjs/hash
Advanced tools
Comparing version 4.0.0 to 5.0.0
declare module '@ioc:Adonis/Core/Hash' { | ||
import { IocContract } from '@adonisjs/fold'; | ||
import { ManagerContract } from '@poppinss/manager'; | ||
@@ -9,5 +10,3 @@ /** | ||
ids: string[]; | ||
params: { | ||
[key: string]: string; | ||
}; | ||
params?: any; | ||
/** | ||
@@ -111,3 +110,3 @@ * Hash plain text value using the default mapping | ||
*/ | ||
export interface HashContract extends ManagerContract<HashDriverContract, HashDriverContract, { | ||
export interface HashContract extends ManagerContract<IocContract, HashDriverContract, HashDriverContract, { | ||
[P in keyof HashersList]: HashersList[P]['implementation']; | ||
@@ -122,5 +121,8 @@ }> { | ||
/** | ||
* Fake/restore hash implementations | ||
* Fake hash | ||
*/ | ||
fake(): void; | ||
/** | ||
* Remove fake | ||
*/ | ||
restore(): void; | ||
@@ -127,0 +129,0 @@ /** |
@@ -1,4 +0,1 @@ | ||
/** | ||
* @module @adonisjs/hash | ||
*/ | ||
import { IocContract } from '@adonisjs/fold'; | ||
@@ -5,0 +2,0 @@ export default class HashProvider { |
"use strict"; | ||
/** | ||
* @module @adonisjs/hash | ||
/* | ||
* @adonisjs/hash | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Hash_1 = require("../src/Hash"); | ||
class HashProvider { | ||
@@ -14,3 +18,4 @@ constructor(container) { | ||
const config = this.container.use('Adonis/Core/Config').get('hash', {}); | ||
return new Hash_1.Hash(this, config); | ||
const { Hash } = require('../src/Hash'); | ||
return new Hash(this, config); | ||
}); | ||
@@ -17,0 +22,0 @@ } |
@@ -8,5 +8,2 @@ /// <reference path="../../adonis-typings/hash.d.ts" /> | ||
ids: FakeContract['ids']; | ||
params: { | ||
[key: string]: string; | ||
}; | ||
/** | ||
@@ -13,0 +10,0 @@ * Alias for [[this.make]] |
/// <reference path="../../adonis-typings/hash.d.ts" /> | ||
/// <reference path="../../test-helpers/contracts.d.ts" /> | ||
import { Manager } from '@poppinss/manager'; | ||
import { HashConfig, HashersList, HashContract, HashDriverContract } from '@ioc:Adonis/Core/Hash'; | ||
import { IocContract } from '@adonisjs/fold'; | ||
import { HashConfig, HashersList, HashContract, HashDriverContract, FakeContract } from '@ioc:Adonis/Core/Hash'; | ||
/** | ||
@@ -8,7 +10,11 @@ * The Hash module exposes the API to hash values using an underlying | ||
*/ | ||
export declare class Hash<Config extends HashConfig> extends Manager<HashDriverContract, HashDriverContract, { | ||
export declare class Hash<Config extends HashConfig> extends Manager<IocContract, HashDriverContract, HashDriverContract, { | ||
[P in keyof HashersList]: HashersList[P]['implementation']; | ||
}> implements HashContract { | ||
config: Config; | ||
/** | ||
* Reference to fake driver. Created when `Hash.fake` is called | ||
*/ | ||
private fakeDriver; | ||
protected singleton: boolean; | ||
/** | ||
@@ -21,30 +27,17 @@ * A boolean to know, if hash module is running in fake | ||
/** | ||
* Initiate faking hash calls. All methods invoked on the main hash | ||
* module and the underlying drivers will be faked using the | ||
* fake driver. | ||
* | ||
* To restore the fake. Run the `Hash.restore` method. | ||
*/ | ||
fake(): void; | ||
/** | ||
* Restore fake | ||
*/ | ||
restore(): void; | ||
/** | ||
* Validate config | ||
*/ | ||
private validateConfig; | ||
protected singleton: boolean; | ||
/** | ||
* Pulling the default driver name from the user config. | ||
*/ | ||
protected getDefaultMappingName(): string; | ||
protected getDefaultMappingName(): "bcrypt" | "argon"; | ||
/** | ||
* Returns the config for a mapping | ||
*/ | ||
protected getMappingConfig(name: string): any; | ||
protected getMappingConfig(name: keyof HashersList): import("@ioc:Adonis/Core/Hash").BcryptConfig | import("@ioc:Adonis/Core/Hash").ArgonConfig; | ||
/** | ||
* Returns the driver name for a mapping | ||
*/ | ||
protected getMappingDriver(name: string): string | undefined; | ||
protected getMappingDriver(name: keyof HashersList): string | undefined; | ||
/** | ||
@@ -66,2 +59,14 @@ * Creating bcrypt driver. The manager will call this method anytime | ||
/** | ||
* Initiate faking hash calls. All methods invoked on the main hash | ||
* module and the underlying drivers will be faked using the | ||
* fake driver. | ||
* | ||
* To restore the fake. Run the `Hash.restore` method. | ||
*/ | ||
fake(): void; | ||
/** | ||
* Restore fake | ||
*/ | ||
restore(): void; | ||
/** | ||
* Alias for [[this.make]] | ||
@@ -85,3 +90,6 @@ */ | ||
*/ | ||
use(name?: string): any; | ||
use<K extends keyof HashersList>(name?: K): import("@ioc:Adonis/Core/Hash").BcryptContract | import("@ioc:Adonis/Core/Hash").ArgonContract | FakeContract | { | ||
argon: import("@ioc:Adonis/Core/Hash").ArgonContract; | ||
bcrypt: import("@ioc:Adonis/Core/Hash").BcryptContract; | ||
}[K]; | ||
} |
@@ -34,18 +34,2 @@ "use strict"; | ||
/** | ||
* Initiate faking hash calls. All methods invoked on the main hash | ||
* module and the underlying drivers will be faked using the | ||
* fake driver. | ||
* | ||
* To restore the fake. Run the `Hash.restore` method. | ||
*/ | ||
fake() { | ||
this.fakeDriver = this.fakeDriver || this.createFake(); | ||
} | ||
/** | ||
* Restore fake | ||
*/ | ||
restore() { | ||
this.fakeDriver = undefined; | ||
} | ||
/** | ||
* Validate config | ||
@@ -102,2 +86,18 @@ */ | ||
/** | ||
* Initiate faking hash calls. All methods invoked on the main hash | ||
* module and the underlying drivers will be faked using the | ||
* fake driver. | ||
* | ||
* To restore the fake. Run the `Hash.restore` method. | ||
*/ | ||
fake() { | ||
this.fakeDriver = this.fakeDriver || this.createFake(); | ||
} | ||
/** | ||
* Restore fake | ||
*/ | ||
restore() { | ||
this.fakeDriver = undefined; | ||
} | ||
/** | ||
* Alias for [[this.make]] | ||
@@ -145,5 +145,5 @@ */ | ||
} | ||
return super.use(name); | ||
return name ? super.use(name) : super.use(); | ||
} | ||
} | ||
exports.Hash = Hash; |
# The MIT License | ||
Copyright 2019 thetutlage, contributors | ||
Copyright 2020 Harminder virk, contributors | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
{ | ||
"name": "@adonisjs/hash", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Multi driver hash module with support for PHC string formats", | ||
@@ -17,3 +17,2 @@ "main": "build/providers/HashProvider", | ||
"test": "node japaFile.js", | ||
"lint": "eslint . --ext=.ts", | ||
"clean": "del build", | ||
@@ -25,3 +24,6 @@ "compile": "npm run lint && npm run clean && tsc", | ||
"version": "npm run build", | ||
"format": "prettier --write ." | ||
"format": "prettier --write .", | ||
"prepublishOnly": "npm run build", | ||
"lint": "eslint . --ext=.ts", | ||
"sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json adonisjs/hash" | ||
}, | ||
@@ -44,5 +46,6 @@ "repository": { | ||
"devDependencies": { | ||
"@adonisjs/config": "^1.1.0", | ||
"@adonisjs/fold": "^6.3.5", | ||
"@adonisjs/mrm-preset": "^2.3.7", | ||
"@types/node": "^14.0.14", | ||
"@adonisjs/mrm-preset": "^2.4.0", | ||
"@types/node": "^14.0.24", | ||
"argon2": "^0.26.2", | ||
@@ -53,11 +56,11 @@ "bcrypt": "^5.0.0", | ||
"del-cli": "^3.0.1", | ||
"doctoc": "^1.4.0", | ||
"eslint": "^7.4.0", | ||
"eslint": "^7.5.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-adonis": "^1.0.14", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"github-label-sync": "^2.0.0", | ||
"husky": "^4.2.5", | ||
"japa": "^3.1.1", | ||
"mrm": "^2.3.3", | ||
"np": "^6.3.0", | ||
"np": "^6.3.2", | ||
"npm-audit-html": "^1.4.1", | ||
@@ -68,3 +71,3 @@ "phc-argon2": "^1.0.10", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.9.6" | ||
"typescript": "^3.9.7" | ||
}, | ||
@@ -81,3 +84,3 @@ "nyc": { | ||
"hooks": { | ||
"pre-commit": "doctoc README.md --title='## Table of contents' && git add README.md && npm audit --production --json | ./node_modules/.bin/npm-audit-html && git add npm-audit.html", | ||
"pre-commit": "npm audit --production --json | ./node_modules/.bin/npm-audit-html && git add npm-audit.html", | ||
"commit-msg": "node ./node_modules/@adonisjs/mrm-preset/validateCommit/conventional/validate.js" | ||
@@ -97,6 +100,6 @@ } | ||
"@phc/format": "^1.0.0", | ||
"@poppinss/manager": "^3.0.1", | ||
"@poppinss/utils": "^2.2.7" | ||
"@poppinss/manager": "^3.0.4", | ||
"@poppinss/utils": "^2.3.0" | ||
}, | ||
"optionalDependencies": {} | ||
} |
106
README.md
<div align="center"> | ||
<img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1564392111/adonis-banner_o9lunk.png" width="600px"> | ||
<img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1558612869/adonis-readme_zscycu.jpg" width="600px"> | ||
</div> | ||
# Password hashing | ||
> Module to hash values with support for [PHC string format](https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md) | ||
<br /> | ||
[![circleci-image]][circleci-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] | ||
<div align="center"> | ||
<h3>AdonisJS Hash Provider</h3> | ||
<p>A multi driver hash provider to hash values (usually passwords). The hash output follows the <a href="https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md"> PHC format spec. </a></p> | ||
</div> | ||
This module is used by [AdonisJs](https://adonisjs.com) to hash the user password with first class support for upgrading logic. A big thanks to the author of [uphash](https://github.com/simonepri/upash), who inspired me to use [PHC string format](https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md). I would have used uphash directly, but the user facing API is different from what I desire. | ||
<br /> | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
## Table of contents | ||
<div align="center"> | ||
- [Features](#features) | ||
- [Usage](#usage) | ||
- [Using with AdonisJs](#using-with-adonisjs) | ||
- [Switching drivers](#switching-drivers) | ||
- [Audit report](#audit-report) | ||
[![circleci-image]][circleci-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![audit-report-image]][audit-report-url] | ||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
</div> | ||
## Features | ||
1. Support for multiple hashing algorithms. | ||
2. Option to extend and add your own hashing algorithms. | ||
3. Wraps the hash output to a [PHC string format](https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md), this allows upgrading user passwords, when the underlying configuration changes. | ||
<div align="center"> | ||
<h3> | ||
<a href="https://preview.adonisjs.com"> | ||
Website | ||
</a> | ||
<span> | </span> | ||
<a href="https://preview.adonisjs.com/guides/security/hash"> | ||
Guides | ||
</a> | ||
<span> | </span> | ||
<a href="CONTRIBUTING.md"> | ||
Contributing | ||
</a> | ||
</h3> | ||
</div> | ||
## Usage | ||
<div align="center"> | ||
<sub>Built with ❤︎ by <a href="https://twitter.com/AmanVirk1">Harminder Virk</a> | ||
</div> | ||
Install the package from npm registry as follows: | ||
```sh | ||
npm i @adonisjs/hash | ||
# yarn | ||
yarn add @adonisjs/hash | ||
``` | ||
and then use it as follows: | ||
```ts | ||
import { Hash } from '@adonisjs/hash/build/standalone' | ||
const hash = new Hash({}, config) | ||
const hashedValue = await hash.hash('password') | ||
await hash.verify(hashedValue) | ||
await hash.needsRehash(hashedValue) // false | ||
``` | ||
## Using with AdonisJs | ||
**The `@adonisjs/core` module includes this module by default**. However, here's how you can set it up manually. | ||
```ts | ||
const providers = [ | ||
'@adonisjs/hash' | ||
] | ||
``` | ||
And then also register the typings file inside `tsconfig.json` file. | ||
```json | ||
{ | ||
"files": ["./node_modules/@adonisjs/hash/build/adonis-typings/hash.d.ts"] | ||
} | ||
``` | ||
And use it as follows: | ||
```ts | ||
import Hash from '@ioc:Adonis/Core/Hash' | ||
await Hash.hash('password') | ||
``` | ||
## Switching drivers | ||
You can switch drivers using the `use` method. | ||
```ts | ||
await Hash.use('bcrypt').hash('password') | ||
``` | ||
## Audit report | ||
[Click here](https://htmlpreview.github.io/?https://github.com/adonisjs/hash/blob/develop/npm-audit.html) to see the latest npm audit report. | ||
[circleci-image]: https://img.shields.io/circleci/project/github/adonisjs/hash/master.svg?style=for-the-badge&logo=circleci | ||
@@ -98,1 +51,4 @@ [circleci-url]: https://circleci.com/gh/adonisjs/hash "circleci" | ||
[license-url]: LICENSE.md "license" | ||
[audit-report-image]: https://img.shields.io/badge/-Audit%20Report-blueviolet?style=for-the-badge | ||
[audit-report-url]: https://htmlpreview.github.io/?https://github.com/adonisjs/hash/blob/develop/npm-audit.html "audit-report" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
747
27468
24
54
Updated@poppinss/manager@^3.0.4
Updated@poppinss/utils@^2.3.0