How to validate Password is strong or not in ReactJS?
Password must be strong so that hackers can not hack them easily. The following example shows how to check the password strength of the user input password in ReactJS.
isStrongPassword(str [, options])
Parameters: This function accepts two parameters as mentioned above and described below:
- str: It is the input value of the string type.
- options: It is an optional parameter. These are options that are checked for the input password. For example minLength, minLowercase, etc.
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
Step 3: After creating the ReactJS application, Install the validator module using the following command:
npm install validator
Project Structure: It will look like the following.
App.js: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.
Step to Run Application: Run the application using the following command from the root directory of the project:
- The following will be the output if the user enters a weak password.
- The following will be the output if the user enters a strong password.