Skip to content

Commit ff53224

Browse files
committed
adding argon2 verify
1 parent 85606ae commit ff53224

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/password-hashers/argon2-wrapper.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,29 @@ import koffi from "koffi";
44
export class Argon2Wrapper {
55
private lib;
66
private argon2_hash: Function;
7+
private argon2_verify: Function;
78

89
constructor() {
910
this.lib = (os.platform() === "win32") ? koffi.load(global.pathToWindowsDll) : koffi.load(global.pathToLinuxSO);
10-
this.argon2_hash = this.lib.func("argon2_hash", 'string', ['string'])
11+
this.argon2_hash = this.lib.func("argon2_hash", 'string', ['string']);
12+
this.argon2_verify = this.lib.func("argon2_verify", 'int8', ['string', 'string']);
1113
}
1214

13-
public hashPassword(passwordToHash: string): string | null {
15+
public hashPassword(passwordToHash: string): string {
1416
if (!passwordToHash) {
1517
throw new Error("You must provide a password to hash");
1618
}
1719
return this.argon2_hash(passwordToHash);
1820
}
21+
22+
public verifyPassword(hashedPassword: string, passwordToVerify: string): boolean {
23+
if (!hashedPassword || !passwordToVerify) {
24+
throw new Error("You must provide a hashed password and a non hash password to verify with Argon2");
25+
}
26+
let result: number = this.argon2_verify(hashedPassword, passwordToVerify);
27+
if (result == 0)
28+
return false;
29+
else
30+
return true;
31+
}
1932
}

0 commit comments

Comments
 (0)