small difference

This commit is contained in:
2024-02-03 00:39:27 +01:00
parent c135e4e98a
commit daff03e5f3
9 changed files with 151 additions and 4 deletions
+2
View File
@@ -8,6 +8,8 @@ Guardian is a powerful JavaScript library designed to fortify your application's
This library is easy to integrate into your project and offers a comprehensive set of features, making it a reliable choice for enhancing the security of your application. This library is easy to integrate into your project and offers a comprehensive set of features, making it a reliable choice for enhancing the security of your application.
you can run it with TypeScript or JavaScript.
## Installation ## Installation
To install Guardian, simply run the following command using npm: To install Guardian, simply run the following command using npm:
+6
View File
@@ -0,0 +1,6 @@
import PassCheck from "./passwordcheck";
import JwtAuth from "jsonwebtoken";
import PassPolicy from "./passpolicy";
import RateLimit from "./ratelimit";
import PasswordGenerator from "./passgen";
export { PassCheck, JwtAuth, PassPolicy, RateLimit, PasswordGenerator };
+37
View File
@@ -0,0 +1,37 @@
import * as jwt from 'jsonwebtoken';
export default class JwtAuth {
private JWTSecretKey;
private blacklist;
constructor(JWTSecretKey: string);
generateJWT(payload: {
[key: string]: any;
}, settings?: jwt.SignOptions, secretKey?: string): string;
verifyJWT(token: string, secretKey?: string): jwt.JwtPayload | undefined;
decodeJWT(token: string): string | jwt.JwtPayload | null;
getJWTExpirationDate(token: string): any;
isJWTExpired(token: string): boolean | {
valid: boolean;
message: string;
};
refreshJWT(token: string, settings?: jwt.SignOptions, secretKey?: string): string | {
valid: boolean;
message: string;
};
BlackListJWT(token: string): {
valid: boolean;
message: string;
};
ClearBlackList(): {
valid: boolean;
message: string;
};
GetBlackList(): string[];
RemoveFromBlackList(token: string): {
valid: boolean;
message: string;
};
IsBlackListed(token: string): {
valid: boolean;
message: string;
};
}
+13
View File
@@ -0,0 +1,13 @@
export default class PasswordGenerator {
private options;
constructor(options: {
minLength: number;
maxLength: number;
minLower: number;
minUpper: number;
minNum: number;
minSpecial: number;
specialChars: string;
});
Generate(length?: number): string;
}
+26
View File
@@ -0,0 +1,26 @@
export default class PassPolicy {
private options;
constructor(options: {
minLength: number;
maxLength: number;
minLower: number;
minUpper: number;
minNum: number;
minSpecial: number;
specialChars: string;
});
validate(password: string): {
valid: boolean;
message: string;
} | {
valid: boolean;
message?: undefined;
};
CheckDifference(newPassword: string, oldPassword: string, neededDifference?: number): {
valid: boolean;
message: string;
} | {
valid: boolean;
message?: undefined;
};
}
+15
View File
@@ -0,0 +1,15 @@
export default class PassCheck {
private BcryptSaltRounds;
private PassPolicy;
constructor(BcryptSaltRounds: number, PassPolicyOptions: {
minLength: number;
maxLength: number;
minLower: number;
minUpper: number;
minNum: number;
minSpecial: number;
specialChars: string;
});
verifyPassword(password: string, hash: string): Promise<boolean>;
hashPassword(password: string): Promise<string>;
}
+46
View File
@@ -0,0 +1,46 @@
type Event = {
name: string;
cooldown: number;
maxAttempts: number;
lastAttempt?: number;
attempts?: number[];
};
type user = {
token: string;
events: {
[name: string]: Event;
};
};
export default class RateLimit {
users: {
[token: string]: user;
};
events: {
[name: string]: Event;
};
constructor(users?: {
[token: string]: user;
}, events?: {
[name: string]: Event;
});
addEvent(event: Event): boolean;
removeEvent(name: string): boolean;
addUser(token: string): boolean;
removeUser(token: string): boolean;
attempt(token: string, name: string): boolean;
getEvents(): {
[name: string]: Event;
};
getUsers(): {
[token: string]: user;
};
getEvent(name: string): Event;
getUser(token: string): user;
remainingAttempts(token: string, name: string): number;
resetAttempts(token: string, name: string): boolean;
resetAllAttempts(token: string): boolean;
resetAllUsers(): boolean;
resetEvent(name: string): boolean;
resetUser(token: string): boolean;
}
export {};
+5 -3
View File
@@ -1,8 +1,10 @@
{ {
"name": "@kajvans/auth-guardian", "name": "auth-guardian",
"version": "2.0.0", "version": "2.0.1",
"description": "auth-guardian a library for enhancing application security", "description": "auth-guardian a library for enhancing application security",
"main": "index.js", "main": "./dist/index.js",
"types": "./dist/index.d.ts",
"typings": "./dist/index.d.ts",
"scripts": { "scripts": {
"test": "jest", "test": "jest",
"build": "tsc" "build": "tsc"
+1 -1
View File
@@ -49,7 +49,7 @@
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
/* Emit */ /* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */