update credential.d.ts

This commit is contained in:
Faisal Hakim
2016-08-02 22:12:56 +07:00
parent 6880225cb5
commit d45a96f558
2 changed files with 46 additions and 15 deletions

View File

@@ -1,16 +1,29 @@
/// <reference path="credential.d.ts" />
// all from current main repo examples
import * as credential from 'credential';
credential.hash('password', function(err: Error, hash: string) {
if (err) console.error(err);
else console.log(hash);
var pw = credential();
var newPassword = 'I have a really great password.';
pw.hash(newPassword, function (err, hash) {
if (err) { throw err; }
console.log('Store the password hash.', hash);
});
const hash = '{}';
const password = 'test';
var storedHash = {
"hash": "gNofnhlBl36AdRyktwATxKoqWKa6hsIEzwCmW/YXN//7PtiJwCRbepV9fUKu0L9TJELCKoDiBy6rGM8ov7lg2yLY",
"salt": "yyN3KUzlr4KrKWMM2K3d2Ddxf8OTq+vkKG+mtnmQVIibxSJz8drfzkYzqcH0EM+PVKR/1nClRr/CPDuJsq+FOcIw",
"keyLength": 66,
"hashMethod": "pbkdf2",
"iterations": 181019
};
var userInput = 'I have a really great password.';
credential.verify(hash, password, function(err: Error, isValid: boolean) {
if (err) console.error(err);
else console.log(isValid ? 'Password match' : 'Incorrect password');
pw.verify(storedHash, userInput, function (err, isValid) {
var msg: string;
if (err) { throw err; }
msg = isValid ? 'Passwords match!' : 'Wrong password.';
console.log(msg);
});

View File

@@ -4,15 +4,33 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module 'credential' {
interface defaultOptions {
keyLength: number;
work: number;
hashMethod: string;
}
type HashCallback = (err: Error, hash: string) => void;
type VerifyCallback = (err: Error, isValid: boolean) => void;
interface hashObject {
hash: string;
salt: string;
keyLength: number;
hashMethod: string;
iterations: number;
}
namespace credential {
function hash(password: string, callback: HashCallback): void;
function verify(hash: string, password: string, callback: VerifyCallback): void;
}
type HashCallback = (err: Error, hash: hashObject) => void;
type VerifyCallback = (err: Error, isValid: boolean) => void;
export = credential;
function credential(defaultOptions?: defaultOptions): {
hash(password: string, callback: HashCallback): void;
hash(password: string): Promise<hashObject>;
// iterations(work: number, base): number;
verify(hash: hashObject | string, password: string, callback: VerifyCallback): void;
verify(hash: hashObject | string, password: string): Promise<boolean>;
expired(hash: string, days: number): boolean;
}
namespace credential { }
export = credential;
}