用python實現密碼校驗程序


密碼需要符合下面的要求:

8個字符以上,包含數字,大小寫,開頭不能為特殊字符。

 

#! /usr/bin/python
import re

password = str(input())

def lenOK(pwd):
    if(len(pwd)>=8):
        return True
    else:
        print("WARNING: The password should be at least 8 characters.")
        return False

def numberOK(pwd):
    pattern = re.compile('[0-9]+')
    match = pattern.findall(pwd)
    if match:
        return True
    else:
        print("WARNING: The password should include at least 1 number.")
        return False

def upperOK(pwd):
    pattern = re.compile('[A-Z]+')
    match = pattern.findall(pwd)
    if match:
        return True
    else:
        print("WARNING: The password should include at least 1 upper character.")
        return False

def lowerOK(pwd):
    pattern = re.compile('[a-z]+')
    match = pattern.findall(pwd)
    if match:
        return True
    else:
        print("WARNING: The password should include at least 1 lower character.")
        return False

def symbolOK(pwd):
    pattern = re.compile('^[a-z0-9A-Z]+')
    match = pattern.findall(pwd)
    if match:
        return True
    else:
        print("WARNING: The password should start with numbers or characters.")
        return False

def checkpwd(pwd):
    check = lenOK(pwd) and numberOK(pwd) and upperOK(pwd) and lowerOK(pwd) and symbolOK(pwd)
    if (check):
        print("The password is legal.")
    else:
        print(check)

checkpwd(password)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM