Python Regular Expression checks the validity of the password and the validity of the python password.

Source: Internet
Author: User

Python Regular Expression checks the validity of the password and the validity of the python password.

The customer's system upgrade requires that the user's password comply with certain rules, that is, including uppercase and lowercase letters, numbers, and symbols. The length is no less than 8. Therefore, a simple test program is written with python:

# Encoding = UTF-8 # coding # Name: Module 1 # Purpose: ## Author: Administrator ## Created: 10-06-2014 # Copyright: (c) Administrator 2014 # Licence: <your licence> # Export import redef checklen (pwd): return len (pwd)> = 8def checkContainUpper (pwd): pattern = re. compile ('[A-Z] +') match = pattern. findall (pwd) if match: return True else: return Falsedef checkContainNum (pwd): pattern = re. compile ('[0-9] +') match = pattern. findall (pwd) if match: return True else: return Falsedef checkContainLower (pwd): pattern = re. compile ('[a-z] +') match = pattern. findall (pwd) if match: return True else: return Falsedef checkSymbol (pwd): pattern = re. compile ('([a-z0-9A-Z]) +') match = pattern. findall (pwd) if match: return True else: return Falsedef checkPassword (pwd): # determine whether the password length is valid lenOK = checklen (pwd) # determine whether to include uppercase letters upperOK = checkContainUpper (pwd) # determine whether to include lowercase letters lowerOK = checkContainLower (pwd) # determine whether to include numbers numOK = checkContainNum (pwd) # determine whether the symbol symbolOK = checkSymbol (pwd) print (lenOK) print (upperOK) print (lowerOK) print (numOK) print (symbolOK) is included) return (lenOK and upperOK and lowerOK and numOK and symbolOK) def main (): if checkPassword ('helloworld # 000000'): print ('checked pass') else: print ('check failed ') 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!

Related Article

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.