https://github.com/jonathanprince/url-hash
Node library to add hash parameter for tamper-free urls
https://github.com/jonathanprince/url-hash
Last synced: 4 months ago
JSON representation
Node library to add hash parameter for tamper-free urls
- Host: GitHub
- URL: https://github.com/jonathanprince/url-hash
- Owner: JonathanPrince
- License: mit
- Created: 2015-02-16T14:37:37.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-03-08T17:09:35.000Z (over 11 years ago)
- Last Synced: 2025-01-30T22:46:45.471Z (over 1 year ago)
- Language: JavaScript
- Size: 262 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
});
```