Python uses regular expressions to detect password strength source code sharing

Source: Internet
Author: User

Copy codeThe Code is as follows:
# Encoding = UTF-8
#-------------------------------------------------------------------------------
# Name: Module 1
# Purpose:
#
# Author: Administrator
#
# Created: 10-06-2014
# Copyright: (c) Administrator 2014
# Licence: <your licence>
#-------------------------------------------------------------------------------
Import re
Def checklen (pwd ):
Return len (pwd)> = 8
Def checkContainUpper (pwd ):
Pattern = re. compile ('[A-Z] + ')
Match = pattern. findall (pwd)
If match:
Return True
Else:
Return False
Def checkContainNum (pwd ):
Pattern = re. compile ('[0-9] + ')
Match = pattern. findall (pwd)
If match:
Return True
Else:
Return False
Def checkContainLower (pwd ):
Pattern = re. compile ('[a-z] + ')
Match = pattern. findall (pwd)
If match:
Return True
Else:
Return False
Def checkSymbol (pwd ):
Pattern = re. compile ('([^ a-z0-9A-Z]) + ')
Match = pattern. findall (pwd)
If match:
Return True
Else:
Return False
Def checkPassword (pwd ):
# Determine whether the password length is valid
LenOK = checklen (pwd)
# Determine whether an uppercase letter is contained
UpperOK = checkContainUpper (pwd)
# Determine whether a lowercase letter is contained
LowerOK = checkContainLower (pwd)
# Determine whether a number is included
NumOK = checkContainNum (pwd)
# Determine whether a symbol is contained
SymbolOK = checkSymbol (pwd)
Print (lenOK)
Print (upperOK)
Print (lowerOK)
Print (numOK)
Print (symbolOK)
Return (lenOK and upperOK and lowerOK and numOK and symbolOK)

Def main ():
If checkPassword ('helloworld #123 '):
Print ('detected pass ')
Else:
Print ('failed detection ')

If _ name _ = '_ main __':
Main ()

There are not many regular expressions at ordinary times. I don't know how to write a regular expression to meet the requirements. I am using a stupid method. Please kindly advise if I have a regular expression test!

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.