Verify password strength with a regular expression

Source: Internet
Author: User
Private int checksecurity (string PWD) {return RegEx. Replace (PWD, "^ (? :( [A-Z]) | ([A-Z]) | ([0-9]) | (.)) {6 ,}| (.) + $ "," $1 $2 $3 $4 $5 "). length ;}

I have seen many methods on the Internet to verify the password strength, but I will not go into a long story.

Today, I have no intention of discovering a very good method, using regular expressions, and only one sentence is enough.

 

 

Here is a rough introduction:

Password characters include lowercase letters, uppercase letters, numbers, and symbols;

This regular expression will get five capture groups. The first four capture groups will tell us how many combinations the string contains (How many matches are returned to indicate how many combinations)

If the string is less than 6 digits, the fifth capture group is obtained. The length is 1 (that is, the intensity is 1). If no input is made, not even the capture group 5 (the intensity is 0)

 

 

Although it is a one-sentence function, it has learned a lot about regular expressions: scope, inclusion, length, capture, and replacement. Worship me!

However, the author seems to have said that it is still to be improved. I think it should be special characters, for example, the problem that full-angle characters cannot be correctly identified. Normal use is not affected.

Verify password strength with a regular expression

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.