hngprojects / hng_boilerplate_nestjs

Description
Apache License 2.0
182 stars 105 forks source link

[FEAT]PASSWORD VALIDATION IN USER REGISTRATION  #263

Closed EmmanuelJunuior closed 2 weeks ago

EmmanuelJunuior commented 1 month ago

Description

This endpoint ensures that the passwords provided by users during registration meet a specified standard for security and complexity. The validation checks for the presence of at least one uppercase letter, one lowercase letter, one digit, one special character, and a minimum length of 8 characters. This enhances data integrity, improves security, and ensures a better user experience.

Acceptance Criteria

The endpoint /api/v1/user/validate-password is accessible via a POST request. When a valid password format is provided, the endpoint returns a 200 OK status and a message "Password format is valid". When an invalid password format is provided, the endpoint returns a 400 Bad Request status and a message "Password must contain at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least 8 characters long.". Ensure that all unit and integration tests for the password validation feature are comprehensive, accurate, and verify the functionality correctly.

Purpose

To ensure users provide a secure and correctly formatted password during registration, enhancing data integrity in the database, improving security, and ensuring successful authentication.

Requirements

Implement an endpoint to validate the password format. Return appropriate status codes and messages based on the validation result. Ensure secure and efficient processing of validation requests.

Expected Outcome

An API endpoint that validates the password format during user registration and returns appropriate responses.

Tasks

Create an endpoint /api/v1/user/validate-password to validate the password format. Implement server-side logic to handle password format validation requests. Ensure secure handling of user input data. Write unit tests for the password validation endpoint. Perform security testing to ensure data protection and compliance.

Endpoint URL: [POST] /api/v1/user/register/

Request Body: { "password": "string" }

Successful Response: Status code: 200 OK { "message": "Registration successful", "data": { "password": "string" } }

Error Response: Status code: 400 BAD REQUEST { "error": { "password": [ "Password must contain at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least 8 characters long." ] } }

Example Request to Validate Password Format curl -X POST "https:///api/v1/user/validate-password/" \ -H "Content-Type: application/json" \ -d '{ "password": "Valid1@password"   }'

markessien commented 1 month ago

duplicate