1. 程式人生 > >《Python編程快速上手》第7.18.1實踐練習

《Python編程快速上手》第7.18.1實踐練習

compile 弱密碼 ssd search code 表達 小寫 strong tro

# -*- coding:utf-8 -*- # 7.18.1 # 強口令檢測 # 寫一個函數,使用正則表達式,確保傳入的口令字符串是強口令 # 長度不少於8個字符,同時包含大小寫,至少有1個數字 import re passd=input("Input your password:") ch_len=re.compile(r‘.{8,}‘) ch_uppercase=re.compile(r‘[A-Z]{1,}‘) ch_case=re.compile(r‘[a-z]{1,}‘) ch_number=re.compile(r‘\d{1,}‘) if ch_len.search(passd): if not ch_case.search(passd) or not ch_uppercase.search(passd) or not ch_number.search(passd) : print("弱密碼") else: print("strong enough") else: print("length less then 8")

《Python編程快速上手》第7.18.1實踐練習