Skip to content

Commit d5fa4c5

Browse files
committed
Scrypt wrapper
1 parent 93a3d06 commit d5fa4c5

File tree

13 files changed

+49
-12
lines changed

13 files changed

+49
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ bcrypt = "0.15.0"
1313
napi = "2"
1414
napi-derive = "2"
1515
rand = "0.8.5"
16+
scrypt = "0.11.0"
1617

1718
[build-dependencies]
1819
napi-build = "1"

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ export function argon2Hash(password: string): string
77
export function argon2Verify(hashedPassword: string, passwordToVerify: string): boolean
88
export function bcryptHash(passwordToHash: string): string
99
export function bcryptVerify(hashedPassword: string, passwordToVerify: string): boolean
10+
export function scryptHash(passwordToHash: string): string
11+
export function scryptVerify(hashedPassword: string, passwordToVerify: string): boolean

index.node

28 KB
Binary file not shown.

src-ts/password-hashers/argon2-wrapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {argon2Hash, argon2Verify} from "./../../index";
2-
import { IPasswordHasherBase, PasswordHasherBase } from "./password-hasher-base";
2+
import { IPasswordHasherBase} from "./password-hasher-base";
33

4-
export class Argon2Wrapper extends PasswordHasherBase implements IPasswordHasherBase {
4+
export class Argon2Wrapper implements IPasswordHasherBase {
55
public hashPassword(password: string): string {
66
if (!password){
77
throw new Error("You must provide a password to hash with Argon2");

src-ts/password-hashers/bcrypt-wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IPasswordHasherBase, PasswordHasherBase } from "./password-hasher-base";
1+
import { IPasswordHasherBase } from "./password-hasher-base";
22
import { bcryptHash, bcryptVerify } from "./../../index";
33

44
export class BCryptWrapper implements IPasswordHasherBase {

src-ts/password-hashers/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Argon2Wrapper } from "./argon2-wrapper"
22
import { BCryptWrapper } from "./bcrypt-wrapper"
3+
import { ScryptWrapper } from "./scrypt-wrapper"
34

45
import { PasswordHasherType } from "./password-hasher-type"
56
import { PasswordHasherFactory } from "./password-hasher-factory"
67

7-
export {PasswordHasherFactory, PasswordHasherType, BCryptWrapper, Argon2Wrapper}
8+
export {PasswordHasherFactory, PasswordHasherType, BCryptWrapper, Argon2Wrapper, ScryptWrapper}

src-ts/password-hashers/password-hasher-base.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
export abstract class PasswordHasherBase implements IPasswordHasherBase {
2-
abstract hashPassword(password: string): string;
3-
abstract verifyPassword(hashedPassword: string, passwordToVerify: string): boolean;
4-
}
5-
6-
71
export interface IPasswordHasherBase {
82
hashPassword(password: string): string;
93
verifyPassword(hashedPassword: string, passwordToVerify: string): boolean;

src-ts/password-hashers/password-hasher-factory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Argon2Wrapper } from "./argon2-wrapper";
22
import { BCryptWrapper } from "./bcrypt-wrapper";
33
import { PasswordHasherType } from "./password-hasher-type";
4+
import { ScryptWrapper } from "./scrypt-wrapper";
45

56
export class PasswordHasherFactory {
67
static getHasher(type: PasswordHasherType): any {
@@ -11,6 +12,7 @@ export class PasswordHasherFactory {
1112
hasher = new BCryptWrapper();
1213
break;
1314
case PasswordHasherType.Scrypt:
15+
hasher = new ScryptWrapper();
1416
break;
1517
}
1618
return hasher;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { scryptHash, scryptVerify } from "../../index";
2+
import { IPasswordHasherBase } from "./password-hasher-base";
3+
4+
export class ScryptWrapper implements IPasswordHasherBase {
5+
6+
public hashPassword(password: string): string {
7+
if (!password){
8+
throw new Error("You must provide a password to hash with Scrypt");
9+
}
10+
return scryptHash(password);
11+
}
12+
13+
public verifyPassword(hashedPassword: string, passwordToVerify: string): boolean {
14+
if (!hashedPassword || !passwordToVerify) {
15+
throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
16+
}
17+
return scryptVerify(hashedPassword, passwordToVerify);
18+
}
19+
20+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod password_hashers {
22
pub mod argon2;
33
pub mod bcrypt;
4+
pub mod scrypt;
45
}

0 commit comments

Comments
 (0)