Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jonathanprince/url-hash

Node library to add hash parameter for tamper-free urls
https://github.com/jonathanprince/url-hash

Last synced: 11 days ago
JSON representation

Node library to add hash parameter for tamper-free urls

Awesome Lists containing this project

README

        

# url-hash
Node library to add hash parameter for tamper-free urls

**NOTE:**
This module is not intended for applications involving sensitive data.
It provides a simple restriction to avoid tampering with url parameters,
or to add a basic expiry time to a link.

## Basic Usage

### Add hash to url

```js

// require library
var urlHash = require('url-hash');

var url = 'http://www.example.com/page?id=4';

// add hash to url
var newUrl = urlHash.create(url);

```

### Verify Url

```js

// require library
var urlHash = require('url-hash');

// check integrity of url
var result = urlHash.check('url/to/verify');

/*

result will either:
1. equal true if the url is unchanged
2. equal false if the url has been changed

*/

// check can also use a callback
urlHash.check('url/to/verify', function(res){
result = res;
});

```

## Configuration options

This library currently offers the following configuration options:

- salt
- expire
- hash key name
- expire key name

```js

urlHash.config({
salt: 'someUniqueCustomSalt', // use custom salt
expire: 60000, // url expires after 1 minute
hashKey: 'myCustomHashKeyName', // use custom name for hash parameter
expKey: 'myCustomExpiryName' // custom name for expire parameter
});

```