Validate passwords with JavaScript

Walter Nascimento
Walter Nascimento | EN
2 min readNov 17, 2021

Using JS to validate strong passwords

[Clique aqui para ler em português]

Simple project to validate password cracking difficulty, using javascript to set as strong password.

Code

First let’s create the interface, we’ll do something simple, using just HTML.

HTML Code

In this code we have only one input that will receive the password and the span where it will be displayed if the password is strong, medium or weak.

JS Code

Here we have the javascript code that does all the magic, where we first get the password elements and the span element, in the password element we add a listening that is activated whenever it receives some data and calls the validPassword function.

in validPassword the input data is checked and compared with the Regex, if the password entered is valid in some regex it is weak, if it is valid in more than one it is average and if it is valid in all it is strong.

To make the password more valid, a minimum length was added for each password, but of course it can be edited to make it more compatible with your project.

ready simple like that.

Demo

See below for the complete working project.

Youtube

If you prefer to watch it, see the development on youtube.

Thanks for reading!

If you have any questions, complaints or tips, you can leave them here in the comments. I will be happy to answer!

😊😊 See you later! 😊😊

--

--