1.0.0 • Published 5 months ago

@josephadogeridev/auth-credential-validator-js v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Auth Credential Validator JS

Version: 1.0.0 Date: June 2, 2025


Description

This is a javascript npm package for both frontend and backend Applications (Express + Node + React + React Native) which validate credentials (username, email and password) using dynamic regex field.

Authors

@jadogeri

Repository

https://github.com/jadogeri/Auth-Credential-Validator-JS.git

Registory

https://www.npmjs.com/package/@josephadogeridev/auth-credential-validator-js

Screenshots

Screenshot 1screenshot 2

Table of Contents

1. Introduction

1.1 Purpose

This document outlines the package architecture, components, and design considerations for Auth Credential Validator JS package. The goal is to provide support in validating user credentials, ensuring credentials adhere to standards for most online accounts.

1.2 Scope

This package will allow users to:

  • Accept valid credentials (username, email and password).
  • Resolve undefined and null values as inputs.
  • Provide ability to alter regular expression used to validate credentials.
  • Render results of credentials after test.

1.3 Intended Audience

  • Junior or Senior developers.
  • beginners learning javascript.

2. Technology Stack

  • Programming Languages: Javascript
  • IDE: Visual Studio Code (VSCode)
  • Test: Jest
  • Plugins: Early AI
  • Registory: NPM (Node Package Manager)
  • Source Control: Git and GitHub
  • CI/CD: GitHub Actions
  • Code Analysis: SonarQube

3. Data Design

3.1 Data Entities and Relationships

EntityDescription
CREDENTIALUser account information.
VALIDATORValidates auth information of Users.

4. Usage

4.1 install dependency

1 Type npm install @josephadogeridev/auth-credential-validator-js to install dependencies.

  npm install @josephadogeridev/auth-credential-validator-js

4.2 Classes and Methods

This project includes the following core components:

4.2.1 Credential Class

The Credential class represents a single credential with its attributes and methods.

  • Attributes:
    • username (string): The username of the credential.
    • email (string): The email of the credential.
    • password (string): The password of the credential.
  • Methods:
    • constructor(username ,email ,password): The constructor method to initialize a new Credential object.
      • Parameters:
        • username (string): The username of the credential.
        • email (string): The email of the credential.
        • password (string): The password of the credential.
      • Description: Creates a new Credential instance with the provided username, email, and password.
    • getUsername(): Returns a string containing the credential's username.
      • Description: Retrieves the username as a readable string.
    • getEmail(): Returns a string containing the credential's email.
      • Description: Retrieves the email as a readable string.
    • getPassword(): Returns a string containing the credential's password.
      • Description: Retrieves the password as a readable string.
    • setUsername(username): Updates the username attribute.
      • Parameters:
        • username (string ): The new username of a credential.
      • Description: updates the username of the credential object.
    • setEmail(email): Updates the email attribute.
      • Parameters:
        • email (string ): The new email of a credential.
      • Description: updates the email of the credential object.
    • setPassword(password): Updates the password attribute.
      • Parameters:
        • password (string ): The new password of a credential.
      • Description: updates the password of the credential object.

4.2.2 Validator Class

The Validator class represents a single validator with its attributes and methods.

  • Attributes:
    • credential (RegExp object): The credential object of the validator.
    • usernameRegex (string): The username regex of the validator.
    • emailRegex (string): The email regex of the validator.
    • passwordRegex (string): The password regex of the validator.
  • Methods:
    • constructor(username, email, password): The constructor method to initialize a new Validator object.
      • Parameters:
        • username (string): The initial username of the credential object.
        • email (string): The initial email of the credential object.
        • password (string): The initial password of the credential object.
      • Description: Creates a new Validator instance with optional username, email, and password.
    • validateUsername(): Returns a boolean containing the Validator's username test result.
      • Description: Tests if Credential's username is valid then retrieves the result.
    • validateEmail(): Returns a boolean containing the Validator' email test result.
      • Description: Tests if Credential's email is valid then retrieves the result.
    • validatePassword(): Returns a boolean containing the Validator' password test result.
      • Description: Tests if Credential's password is valid then retrieves the result .
    • setUsernameRegex(regex): Updates the usernameRegex attribute.
      • Parameters:
        • regex (RegExp ): The new usernameRegex of a validator.
      • Description: updates the usernameRegex attribute of the validator object.
    • setEmailRegex(regex): Updates the emailRegex attribute.
      • Parameters:
        • regex (RegExp ): The new emailRegex of a validator.
      • Description: updates the emailRegex attribute of the validator object.
    • setPasswordRegex(password): Updates the passwordRegex attribute.
      • Parameters:
        • regex (RegExp ): The new passwordRegex of a validator.
      • Description: updates the passwordRegex attribute of the validator object.
    • getCredential(): Returns a credential object.
      • Description: Retrieves the credential attribute of a validator .

4.3 code snippet

import Validator from "auth-credential-validator-js"
const validator = new Validator("jose mourinho","jose mpurinho@gmailcom","rtw5wwvw+-*/twrt");

console.log("*********** Testing Package before publish using npm link***********\n\n");
console.log("validator Object : ",validator);
console.log("validator Credentials : ",validator.getCredential());
console.log("validate email :" ,validator.validateEmail());
console.log("validate username :" ,validator.validateUsername());
console.log("validate password :" ,validator.validatePassword());

validator.credential.setEmail("joseMourinho@gmail.com");
validator.credential.setUsername("Josemourinho");
validator.credential.setPassword("Mourinho!trebl3");

console.log("\n\n*********** test new credentials***********\n\n");

console.log("validate email :" ,validator.validateEmail());
console.log("validate username :" ,validator.validateUsername());
console.log("validate password :" ,validator.validatePassword());

console.log("\n\n*********** update regex ***********\n\n");
validator.setEmailRegex(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/)
validator.setUsernameRegex(/^(?=.*[A-Za-z0-9]).{3,30}$/);
validator.setPasswordRegex(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#\$%\^&\*])[\w!@#\$%\^&\*]{8,30}$/);

5. Tests

5.1 Test from node_modules

1 navigate to cd @josephadogeridev/auth-credential-validator-js directory using command below

  cd node_modules/@josephadogeridev/auth-credential-validator-js  

2 type npm run test to run unit tests

  npm run test

npm.io

5.2 Test from npm link

Note : this test was done pre publish to npm manager

1 In the root of package run npm link to create symbolic link between a local package under development and another Node.js project that wants to use it as a dependency.

  npm link

npm.io

2 Create a new directory, copy script.js in node_modules/@josephadogeridev/Auth-Credential-Validator-JS directory to new folder.

3 Run command npm link @josephadogeridev/Auth-Credential-Validator-JS to install node with created package.

npm.io

3 Type node script.js to test package.

  code script.js

npm.io

6. License

LICENSE


7. References