English | Português
API that receives a password (string) as a parameter and validates if it is a valid password by returning a boolean.
- Requirements
- How to run the project
- Implementation choices
- Request method
- Request types
- HTTP response codes
- Constraints to validate password:
- Request examples
- Node v18.14.0 or later
- NPM v9.4.2 or later
-
Clone the repository using one of the following commands:
git clone https://github.com/luis-saes/valid-password-api.git
for HTTPS;git clone git@github.com:luis-saes/valid-password-api.git
for SSH;gh repo clone luis-saes/valid-password-api
for GitHub CLI;
-
Navigate to the project directory and install the dependencies using the command
npm install
-
Run the project using the command
npm run init
- Node.js: tool chosen for having high familiarity and for allowing fast and efficient development of a simple API.
- Express.js: framework chosen for allowing the creation of routes and the handling of requests and responses in a clear and fast way.
- Jest: framework chosen to carry out unit tests, ensuring the proper functioning of the password validation module, chosen for having excellent documentation and being easy to use.
- TypeScript: language chosen for allowing code typing, facilitating its reading, maintenance and scalability.
- ESLint and Prettier: tools chosen to standardize and format the code, ensuring high consistency between different developers of the same tool.
- Clean Code: methodology used to make the code more readable and easier to maintain, carefully choosing names, organization and structure of the code and avoiding unnecessary repetitions.
- SOLID: the applicable principles were used to try to guarantee that the code is maintainable and scalable, trying to assure that each class has only one responsibility.
- MVC: architecture pattern chosen to separate the application into different components. While not necessary for a simple application like this, the choice was made to ensure the code is maintainable and scalable.
- REST: standard chosen to ensure that the API is easy to use, lightweight, independent and flexible.
This API only uses the POST request method.
Method | URL | Description |
---|---|---|
POST |
http://localhost:3000/validate-password |
Sends a password in string format and receives a boolean indicating its validity |
Code | Title | Description |
---|---|---|
200 |
OK |
The request was successful |
400 |
Bad Request |
The request could not be understood due to syntax |
To be valid, the password must have:
- At least 9 characters
- At least 1 digit
- At least 1 lowercase letter
- At least 1 uppercase letter
- At least one special character (!@#$%^&*()-+)
- No repeated characters
- No whitespaces
All requests are made sending a JSON object with the password to be validated.
JSON object format:
{
"password": "password_to_be_validated"
}
To send a request to the API, you can use:
cURL example - Windows 10:
curl -X POST http://localhost:3000/validate-password ^
-H "Content-Type:application/json" ^
-d {\"password\":\"pasWordN@1\"}
Request:
POST http://localhost:3000/validate-password
{
"password": "paSsVAlid@T0r"
}
Response:
{
"isValid": true
}
Response status: 200
Request:
POST http://localhost:3000/validate-password
{
"password": "false password"
}
Response:
{
"isValid": false
}
Response status: 200
Request:
POST http://localhost:3000/validate-password
{
"password": ""
}
Response: Empty password, please provide a password
Response status: 400