python使用正则表达式判别用户输入密码的强弱并提示
对于用户输入的密码、系统要去分析和判别,密码是否合法是否太简单以至于非常容易被试出来,来提高系统的稳健程度;
密码要强大需要满足:
1,最好9个字符最多20个字符
2,不能是换行或者空格
3,不能连续出现统一字符
4,字符模式不能重复出现(字符模式指的是至少两个字符构成的组合反复出现)
#Categorize Password as Strong or Weak using Regex in Python
# Categorizing password as Strong or# Weak in Python using Regeximport re# Function to categorize passworddef password(v):# the password should not be a# newline or spaceif v == "\n" or v == " ":return "Password cannot be a newline or space!"# the password length should be in# between 9 and 20if 9 <= len(v) <= 20:# checks for occurrence of a character# three or more times in a rowif re.search(r(.)\1\1, v):re