Detect password strength

Source: Internet
Author: User

To register a new account on most platforms, entering a password is a must, and sometimes in order to remind the user to set a relatively secure password, the password strength is detected.

/** * @param input (password box) * @param notice (text hint) * Detect password strength for reference **/function checkpasswordstrength (input  , notice) {var str = [' Password strength: weak ', ' Password strength: Medium ', ' Password strength: strong '],getstrength = function (str) {var strength = 0;if (Str.length < 6) return Strength;if (/\d/.test (str)) strength++; Digital if (/[a-z]/.test (str)) strength++; lowercase if (/[a-z]/.test (str)) strength++; Uppercase if (/\w/.test (str)) strength++; Special character switch (strength) {case 1:return 1;break;case 2:return 2;break;case 3:case 4:return str.length < 3:4break; }},strong;input.oninput = Input.onpropertychange = function () {strong = Getstrength (input.value); switch (strong {Case 0:notice.innerhtml = '; break;case 1:case 2:notice.innerhtml = str[0];break;case 3:notice.innerhtml = str[1]; Break;case 4:notice.innerhtml = Str[2];break;}}} Usevar input = document.getElementById (' password '), notice = document.getElementById (' notice '); Checkpasswordstrength (Input,notice);} 

A very simple detection function, when the user input detection password whether there are numbers, lowercase letters, uppercase, special symbols, according to the input to determine the strength of the password.

It uses the event:oninput, Onpropertychange to listen for input box value changes.

  

Detect password strength

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.