This time I will bring you the use of regular expressions to verify password strength, and what are the precautions for using regular expressions to verify password strength. The following is a practical case, let's take a look.
Preface
##When users register, password regularization will be used test. To write a correct regular expression, you must first define the expression rules.
Option 1 (Simple) Assume that password verification is defined as follows:
- Shortest 6 digits, up to 16 digits {6,16}
- can include lowercase letters [a-z] and uppercase letters [A-Z]
- Can contain numbers [0-9]
- Can contain underscores [_] and minus signs [-]
- According to the above rules, it is easy The regular literal definition is given as follows:
var pattern = /^[\w_-]{6,16}$/;
Scheme 1 AnalysisLiteral/ /
regular expression A literal is defined as a character contained between a pair of slashes (/), for example:
var pattern = /s$/;
The above literal matches all strings ending with the letter "s".
Character class [ ]Put characters in square brackets to form a character class. A character class can match any character it contains. Therefore, the regular expression /[abc]/ matches any of the letters "a", "b", or "c".
Character classes may use hyphens to represent
character ranges. To match Latin lowercase letters use /[a-z]/ .
Character class \wCharacter class \w matches any word composed of ASCII characters, equivalent to [a-zA-Z0-9].
[\w_-] means matching any Latin uppercase and lowercase letters, numbers plus underscores and minus signs.
Repeat {}Use { } in regular expressions to represent the number of times an element repeats.
- {n,m} Match the previous item at least n times, but not more than m times
- {n,} Match the previous item n times or more
- {n} matches the previous item n times
^ Matches the beginning of the string, in multi-line retrieval, matches the beginning of a line
$ Matches the end of the string, in multiple lines During retrieval, match the end of a line/^\w/ and match strings starting with uppercase and lowercase letters or numbers.
Option 1 testThe test results are given as follows:
var pattern = /^[\w_-]{6,16}$/; pattern.test('123456') = true; pattern.test('-ifat33') = true; pattern.test('42du') = false; pattern.test('du42du42du42du421') = false; pattern.test('42du42@') = false;
View source code
According to the test It can be seen from the results that Solution 1 only briefly limits the password and cannot guarantee the strength of the password and the security of the account.
Option 2 (Security) Assume that password verification is defined as follows:
- Shortest 6 digits, up to 16 digits {6,16}
- must contain 1 number
- must contain 2 lowercase letters
- must contain 2 uppercase letters
- must contain 1
- special character According to the above rules, it is easy to give the definition of regular literals as follows:
var pattern = /^.*(?=.{6,16})(?=.*\d)(?=.*[A-Z]{2,})(?=.*[a-z]{2,})(?=.*[!@#$%^&*?\(\)]).*$/;
Analysis of scenario 2
Character class.Character class. Represents any character except newlines and other Unicode line terminators.
Forward lookahead assertion (?= )在符号“(?=” 和 “)” 之间加入一个表达式,它就是一个先行断言,用以说明圆括号内的表达式必须正确匹配。比如: /Java(?=\:)/ 只能匹配Java且后面有冒号的。 该先行断言表示,必须包括一个特殊字符。上述表达式中的10个特殊字符为键盘1,2...0的上档键字符,也可以添加别的特殊字符。注意:如果添加字符是正则表达式中具有特殊含义的,需要在符号前加反斜线(\)转义。 方案2测试 给出测试结果如下: 相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章! 推荐阅读:(?=.*[!@#$%^&*?\(\)])
var pattern = /^.*(?=.{6,16})(?=.*\d)(?=.*[A-Z]{2,})(?=.*[a-z]{2,})(?=.*[!@#$%^&*?\(\)]).*$/;
pattern.test('du42DU!') = true;
pattern.test('duDUd!') = false;
pattern.test('42dud!') = false;
pattern.test('42DUD!') = false;
pattern.test('42duDU') = false;
pattern.test('42duU(') = false;
pattern.test('42dUU!') = false;
The above is the detailed content of Use regular expressions to verify password strength. For more information, please follow other related articles on the PHP Chinese website!

1.使用计算机在没有密码或面容ID的情况下解锁iPhone的第一种方法是使用计算机。您必须在恢复模式下恢复iPhone。完成后,您可以设置iPhone并设置新密码,触控ID,面容ID,或者选择使用您的设备而不使用任何这些。您可以使用Mac甚至WindowsPC进行此过程。请注意:此方法将删除所有内容,并将iPhone恢复出厂设置。如果您已备份数据,则可以在设置iPhone时恢复数据。1.首先,您需要关闭iPhone。2.接下来,执行强制重启以将iPhone置于恢复模式。对于iPhone8或更高版

升级了win101909系统后,可能有的小伙伴们会有想要取消自己电脑锁屏密码的需求。如果不知道应该怎么做的话,小编觉得我们可以在电脑的设置窗口中找到账户选项,具体方法一起来看看吧。win101909如何取消锁屏密码:1、首先按Win+I打开设置界面。2、然后找到账户--登录选项,再进行如图设置即可。win101909取消开机密码登录的方法:1、在运行中执行regedit打开注册表,定位至如下路径:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\Cu

“iPhone不可用”安全功能如何操作?触发“iPhone不可用”消息的基本机制植根于系统设计的安全功能,该功能可跟踪每个不正确的密码条目。这种保护机制从第五次错误尝试解锁设备开始进入高速运转。一旦达到这个里程碑,iPhone就会设置一分钟的临时锁定期,在此期间,任何输入密码的额外尝试都将变得徒劳无功。此锁定持续时间不是静态的,而是遵循不断升级的模式。具体来说,在第五次密码尝试之后,每次后续错误密码尝试都会导致锁定计时器增加一分钟。例如,第六次错误尝试将导致2分钟锁定,第七次错误尝试将导致3分钟

react实现密码隐藏功能的方法:1、添加依赖“import {View,Text,TouchableWithoutFeedback,TextInput,Image,StyleSheet,} from 'react-native';”;2、通过“{this.state.imageState ? (...)}”方法实现密码显示与隐藏功能即可。

保护用户密码是应用程序开发的一个重要方面。保护密码的最佳方法之一是利用哈希计算。散列是将纯文本密码转换为不可转换的固定长度字符序列的过程。在本文中,我们将研究如何在Python中对密码进行哈希处理,讨论其中的语言结构和计算。我们还将提供两个真实的可执行代码示例来演示不同的密码哈希方法。语法为了在Python中对密码进行哈希处理,我们将利用hashlib模块,它提供了不同的哈希算法。利用hashlib散列秘密短语的基本句子结构如下-importhashlibpassword="my_pa

电脑自从诞生以来就很好地被应用在了我们生活的方方面面,现在最新的电脑系统是win10系统,该系统有是经过无数次的测试之后才被推出来的,所以非常地流畅,那么win10怎么设置开机密码?下面,小编给大家带来了win10电脑设置密码的教程,一起来看看吧。1、点击“开始”菜单,然后点击“设置”。2、点击“账户”。3、点击“登录选项”。4、然后点击添加密码。5、接着输入我们的密码以及提示关键词。6、保存之后即是设置好密码了,重启电脑生效。以上就是win10电脑设置密码的教程啦,希望能帮助到大家。

有的朋友新安装了win11系统,但是不知道windows11默认账号密码是什么,担心无法登录和正常使用。其实系统默认一般是没有密码的,我们只需要直接登录就可以了,下面一起来看看吧。windows11默认账号密码是什么:答:默认账号是administrator,没有密码。win11刚刚安装时,使用的默认账号都是“administrator”密码方面,系统安装都是没有默认密码的,不需要密码就能登录。windows11修改账号密码方法1、如果我们想要修改密码的话,可以打开开始菜单的“设置”2、接着点开

我们在无意中进行了一些错误操作,或者是系统自身出现一定的错误时,就可能会出现输入密码进不了桌面一直重启的办法。这时候我们可以在安全模式中进行修复,下面就一起来看具体方法吧。win10输入密码进不了桌面一直重启解决方法1、首先我们长按键盘“shift”点击右下角的电源键,然后选择重启电脑,一直到出现修复界面再松开“shift”键。2、如果我们右下角没有电源键,也可以使用电脑主机的电源键,但是需要连续重启3次或以上才行。3、在出现了修复界面之后,我们点击“查看高级修复选项”。4、选择“疑难解答”。5


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools
