Php password strength detection code

Source: Internet
Author: User
Php password strength detection code
This article introduces a piece of code implemented using php to detect the password strength. For more information, see.

In php programming, especially when users register such a module, there are no more requirements for user password strength.

Currently, many websites detect the password strength to obtain the user password that meets the security requirements. However, some password strength detection functions are built on js or other scripts, which may be damaged by malicious attackers who bypass the password detection.

This section of code is used to check the length, special characters, numbers, and letters. In addition, you can add additional characters to enhance the security of the password.

Check the code as follows:

     = 8 & $ length <= 15) {$ strength + = 1 ;} /*** check if lenth is 16-35 chars ***/if ($ length> = 16 & $ length <= 35) {$ strength + = 2 ;} /*** check if length greater than 35 chars ***/if ($ length> 35) {$ strength + = 3 ;} /*** get the numbers in the password ***/preg_match_all ('/[0-9]/', $ password, $ numbers ); $ strength + = count ($ numbers [0]);/*** check for special chars ***/preg_match_all ('/[|! @ # $ % & * \/= ?,;.: \-_ + ~ ^ \\\]/', $ Password, $ specialchars); $ strength + = sizeof ($ specialchars [0]); /*** get the number of unique chars ***/$ chars = str_split ($ password); $ num_unique_chars = sizeof (array_unique ($ chars )); $ strength + = $ num_unique_chars * 2;/*** strength is a number 1-10; ***/$ strength = $ strength> 99? 99: $ strength; $ strength = floor ($ strength/10 + 1); return $ strength ;} /*** call example ***/$ password = 'php _ tutorials_and_examples! 123 '; echo testPassword ($ password);?>

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.